Line Hotness Optimization Source Inline Context
1

2
/* POSIX module implementation */
3

4
/* This file is also used for Windows NT/MS-Win.  In that case the
5
   module actually calls itself 'nt', not 'posix', and a few
6
   functions are either unimplemented or implemented differently.  The source
7
   assumes that for Windows NT, the macro 'MS_WINDOWS' is defined independent
8
   of the compiler used.  Different compilers define their own feature
9
   test macro, e.g. '_MSC_VER'. */
10

11

12

13
#ifdef __APPLE__
14
   /*
15
    * Step 1 of support for weak-linking a number of symbols existing on
16
    * OSX 10.4 and later, see the comment in the #ifdef __APPLE__ block
17
    * at the end of this file for more information.
18
    */
19
#  pragma weak lchown
20
#  pragma weak statvfs
21
#  pragma weak fstatvfs
22

23
#endif /* __APPLE__ */
24

25
#define PY_SSIZE_T_CLEAN
26

27
#include "Python.h"
28
#include "structmember.h"
29
#ifndef MS_WINDOWS
30
#include "posixmodule.h"
31
#else
32
#include "winreparse.h"
33
#endif
34

35
/* On android API level 21, 'AT_EACCESS' is not declared although
36
 * HAVE_FACCESSAT is defined. */
37
#ifdef __ANDROID__
38
#undef HAVE_FACCESSAT
39
#endif
40

41
#include <stdio.h>  /* needed for ctermid() */
42

43
#ifdef __cplusplus
44
extern "C" {
45
#endif
46

47
PyDoc_STRVAR(posix__doc__,
48
"This module provides access to operating system functionality that is\n\
49
standardized by the C Standard and the POSIX standard (a thinly\n\
50
disguised Unix interface).  Refer to the library manual and\n\
51
corresponding Unix manual entries for more information on calls.");
52

53

54
#ifdef HAVE_SYS_UIO_H
55
#include <sys/uio.h>
56
#endif
57

58
#ifdef HAVE_SYS_TYPES_H
59
#include <sys/types.h>
60
#endif /* HAVE_SYS_TYPES_H */
61

62
#ifdef HAVE_SYS_STAT_H
63
#include <sys/stat.h>
64
#endif /* HAVE_SYS_STAT_H */
65

66
#ifdef HAVE_SYS_WAIT_H
67
#include <sys/wait.h>           /* For WNOHANG */
68
#endif
69

70
#ifdef HAVE_SIGNAL_H
71
#include <signal.h>
72
#endif
73

74
#ifdef HAVE_FCNTL_H
75
#include <fcntl.h>
76
#endif /* HAVE_FCNTL_H */
77

78
#ifdef HAVE_GRP_H
79
#include <grp.h>
80
#endif
81

82
#ifdef HAVE_SYSEXITS_H
83
#include <sysexits.h>
84
#endif /* HAVE_SYSEXITS_H */
85

86
#ifdef HAVE_SYS_LOADAVG_H
87
#include <sys/loadavg.h>
88
#endif
89

90
#ifdef HAVE_LANGINFO_H
91
#include <langinfo.h>
92
#endif
93

94
#ifdef HAVE_SYS_SENDFILE_H
95
#include <sys/sendfile.h>
96
#endif
97

98
#ifdef HAVE_SCHED_H
99
#include <sched.h>
100
#endif
101

102
#if !defined(CPU_ALLOC) && defined(HAVE_SCHED_SETAFFINITY)
103
#undef HAVE_SCHED_SETAFFINITY
104
#endif
105

106
#if defined(HAVE_SYS_XATTR_H) && defined(__GLIBC__) && !defined(__FreeBSD_kernel__) && !defined(__GNU__)
107
#define USE_XATTRS
108
#endif
109

110
#ifdef USE_XATTRS
111
#include <sys/xattr.h>
112
#endif
113

114
#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__APPLE__)
115
#ifdef HAVE_SYS_SOCKET_H
116
#include <sys/socket.h>
117
#endif
118
#endif
119

120
#ifdef HAVE_DLFCN_H
121
#include <dlfcn.h>
122
#endif
123

124
#ifdef __hpux
125
#include <sys/mpctl.h>
126
#endif
127

128
#if defined(__DragonFly__) || \
129
    defined(__OpenBSD__)   || \
130
    defined(__FreeBSD__)   || \
131
    defined(__NetBSD__)    || \
132
    defined(__APPLE__)
133
#include <sys/sysctl.h>
134
#endif
135

136
#ifdef HAVE_LINUX_RANDOM_H
137
#  include <linux/random.h>
138
#endif
139
#ifdef HAVE_GETRANDOM_SYSCALL
140
#  include <sys/syscall.h>
141
#endif
142

143
#if defined(MS_WINDOWS)
144
#  define TERMSIZE_USE_CONIO
145
#elif defined(HAVE_SYS_IOCTL_H)
146
#  include <sys/ioctl.h>
147
#  if defined(HAVE_TERMIOS_H)
148
#    include <termios.h>
149
#  endif
150
#  if defined(TIOCGWINSZ)
151
#    define TERMSIZE_USE_IOCTL
152
#  endif
153
#endif /* MS_WINDOWS */
154

155
/* Various compilers have only certain posix functions */
156
/* XXX Gosh I wish these were all moved into pyconfig.h */
157
#if defined(__WATCOMC__) && !defined(__QNX__)           /* Watcom compiler */
158
#define HAVE_OPENDIR    1
159
#define HAVE_SYSTEM     1
160
#include <process.h>
161
#else
162
#ifdef _MSC_VER         /* Microsoft compiler */
163
#define HAVE_GETPPID    1
164
#define HAVE_GETLOGIN   1
165
#define HAVE_SPAWNV     1
166
#define HAVE_EXECV      1
167
#define HAVE_WSPAWNV    1
168
#define HAVE_WEXECV     1
169
#define HAVE_PIPE       1
170
#define HAVE_SYSTEM     1
171
#define HAVE_CWAIT      1
172
#define HAVE_FSYNC      1
173
#define fsync _commit
174
#else
175
/* Unix functions that the configure script doesn't check for */
176
#define HAVE_EXECV      1
177
#define HAVE_FORK       1
178
#if defined(__USLC__) && defined(__SCO_VERSION__)       /* SCO UDK Compiler */
179
#define HAVE_FORK1      1
180
#endif
181
#define HAVE_GETEGID    1
182
#define HAVE_GETEUID    1
183
#define HAVE_GETGID     1
184
#define HAVE_GETPPID    1
185
#define HAVE_GETUID     1
186
#define HAVE_KILL       1
187
#define HAVE_OPENDIR    1
188
#define HAVE_PIPE       1
189
#define HAVE_SYSTEM     1
190
#define HAVE_WAIT       1
191
#define HAVE_TTYNAME    1
192
#endif  /* _MSC_VER */
193
#endif  /* ! __WATCOMC__ || __QNX__ */
194

195

196
/*[clinic input]
197
# one of the few times we lie about this name!
198
module os
199
[clinic start generated code]*/
200
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=94a0f0f978acae17]*/
201

202
#ifndef _MSC_VER
203

204
#if defined(__sgi)&&_COMPILER_VERSION>=700
205
/* declare ctermid_r if compiling with MIPSPro 7.x in ANSI C mode
206
   (default) */
207
extern char        *ctermid_r(char *);
208
#endif
209

210
#ifndef HAVE_UNISTD_H
211
#if defined(PYCC_VACPP)
212
extern int mkdir(char *);
213
#else
214
#if ( defined(__WATCOMC__) || defined(_MSC_VER) ) && !defined(__QNX__)
215
extern int mkdir(const char *);
216
#else
217
extern int mkdir(const char *, mode_t);
218
#endif
219
#endif
220
#if defined(__IBMC__) || defined(__IBMCPP__)
221
extern int chdir(char *);
222
extern int rmdir(char *);
223
#else
224
extern int chdir(const char *);
225
extern int rmdir(const char *);
226
#endif
227
extern int chmod(const char *, mode_t);
228
/*#ifdef HAVE_FCHMOD
229
extern int fchmod(int, mode_t);
230
#endif*/
231
/*#ifdef HAVE_LCHMOD
232
extern int lchmod(const char *, mode_t);
233
#endif*/
234
extern int chown(const char *, uid_t, gid_t);
235
extern char *getcwd(char *, int);
236
extern char *strerror(int);
237
extern int link(const char *, const char *);
238
extern int rename(const char *, const char *);
239
extern int stat(const char *, struct stat *);
240
extern int unlink(const char *);
241
#ifdef HAVE_SYMLINK
242
extern int symlink(const char *, const char *);
243
#endif /* HAVE_SYMLINK */
244
#ifdef HAVE_LSTAT
245
extern int lstat(const char *, struct stat *);
246
#endif /* HAVE_LSTAT */
247
#endif /* !HAVE_UNISTD_H */
248

249
#endif /* !_MSC_VER */
250

251
#ifdef HAVE_UTIME_H
252
#include <utime.h>
253
#endif /* HAVE_UTIME_H */
254

255
#ifdef HAVE_SYS_UTIME_H
256
#include <sys/utime.h>
257
#define HAVE_UTIME_H /* pretend we do for the rest of this file */
258
#endif /* HAVE_SYS_UTIME_H */
259

260
#ifdef HAVE_SYS_TIMES_H
261
#include <sys/times.h>
262
#endif /* HAVE_SYS_TIMES_H */
263

264
#ifdef HAVE_SYS_PARAM_H
265
#include <sys/param.h>
266
#endif /* HAVE_SYS_PARAM_H */
267

268
#ifdef HAVE_SYS_UTSNAME_H
269
#include <sys/utsname.h>
270
#endif /* HAVE_SYS_UTSNAME_H */
271

272
#ifdef HAVE_DIRENT_H
273
#include <dirent.h>
274
#define NAMLEN(dirent) strlen((dirent)->d_name)
275
#else
276
#if defined(__WATCOMC__) && !defined(__QNX__)
277
#include <direct.h>
278
#define NAMLEN(dirent) strlen((dirent)->d_name)
279
#else
280
#define dirent direct
281
#define NAMLEN(dirent) (dirent)->d_namlen
282
#endif
283
#ifdef HAVE_SYS_NDIR_H
284
#include <sys/ndir.h>
285
#endif
286
#ifdef HAVE_SYS_DIR_H
287
#include <sys/dir.h>
288
#endif
289
#ifdef HAVE_NDIR_H
290
#include <ndir.h>
291
#endif
292
#endif
293

294
#ifdef _MSC_VER
295
#ifdef HAVE_DIRECT_H
296
#include <direct.h>
297
#endif
298
#ifdef HAVE_IO_H
299
#include <io.h>
300
#endif
301
#ifdef HAVE_PROCESS_H
302
#include <process.h>
303
#endif
304
#ifndef VOLUME_NAME_DOS
305
#define VOLUME_NAME_DOS 0x0
306
#endif
307
#ifndef VOLUME_NAME_NT
308
#define VOLUME_NAME_NT  0x2
309
#endif
310
#ifndef IO_REPARSE_TAG_SYMLINK
311
#define IO_REPARSE_TAG_SYMLINK (0xA000000CL)
312
#endif
313
#ifndef IO_REPARSE_TAG_MOUNT_POINT
314
#define IO_REPARSE_TAG_MOUNT_POINT (0xA0000003L)
315
#endif
316
#include "osdefs.h"
317
#include <malloc.h>
318
#include <windows.h>
319
#include <shellapi.h>   /* for ShellExecute() */
320
#include <lmcons.h>     /* for UNLEN */
321
#ifdef SE_CREATE_SYMBOLIC_LINK_NAME /* Available starting with Vista */
322
#define HAVE_SYMLINK
323
static int win32_can_symlink = 0;
324
#endif
325
#endif /* _MSC_VER */
326

327
#ifndef MAXPATHLEN
328
#if defined(PATH_MAX) && PATH_MAX > 1024
329
#define MAXPATHLEN PATH_MAX
330
#else
331
#define MAXPATHLEN 1024
332
#endif
333
#endif /* MAXPATHLEN */
334

335
#ifdef UNION_WAIT
336
/* Emulate some macros on systems that have a union instead of macros */
337

338
#ifndef WIFEXITED
339
#define WIFEXITED(u_wait) (!(u_wait).w_termsig && !(u_wait).w_coredump)
340
#endif
341

342
#ifndef WEXITSTATUS
343
#define WEXITSTATUS(u_wait) (WIFEXITED(u_wait)?((u_wait).w_retcode):-1)
344
#endif
345

346
#ifndef WTERMSIG
347
#define WTERMSIG(u_wait) ((u_wait).w_termsig)
348
#endif
349

350
#define WAIT_TYPE union wait
351
#define WAIT_STATUS_INT(s) (s.w_status)
352

353
#else /* !UNION_WAIT */
354
#define WAIT_TYPE int
355
#define WAIT_STATUS_INT(s) (s)
356
#endif /* UNION_WAIT */
357

358
/* Don't use the "_r" form if we don't need it (also, won't have a
359
   prototype for it, at least on Solaris -- maybe others as well?). */
360
#if defined(HAVE_CTERMID_R) && defined(WITH_THREAD)
361
#define USE_CTERMID_R
362
#endif
363

364
/* choose the appropriate stat and fstat functions and return structs */
365
#undef STAT
366
#undef FSTAT
367
#undef STRUCT_STAT
368
#ifdef MS_WINDOWS
369
#       define STAT win32_stat
370
#       define LSTAT win32_lstat
371
#       define FSTAT _Py_fstat_noraise
372
#       define STRUCT_STAT struct _Py_stat_struct
373
#else
374
#       define STAT stat
375
#       define LSTAT lstat
376
#       define FSTAT fstat
377
#       define STRUCT_STAT struct stat
378
#endif
379

380
#if defined(MAJOR_IN_MKDEV)
381
#include <sys/mkdev.h>
382
#else
383
#if defined(MAJOR_IN_SYSMACROS)
384
#include <sys/sysmacros.h>
385
#endif
386
#if defined(HAVE_MKNOD) && defined(HAVE_SYS_MKDEV_H)
387
#include <sys/mkdev.h>
388
#endif
389
#endif
390

391
#define DWORD_MAX 4294967295U
392

393
#ifdef MS_WINDOWS
394
#define INITFUNC PyInit_nt
395
#define MODNAME "nt"
396
#else
397
#define INITFUNC PyInit_posix
398
#define MODNAME "posix"
399
#endif
400

401
#ifdef MS_WINDOWS
402
/* defined in fileutils.c */
403
PyAPI_FUNC(void) _Py_time_t_to_FILE_TIME(time_t, int, FILETIME *);
404
PyAPI_FUNC(void) _Py_attribute_data_to_stat(BY_HANDLE_FILE_INFORMATION *,
405
                                            ULONG, struct _Py_stat_struct *);
406
#endif
407

408
#ifdef MS_WINDOWS
409
static int
410
win32_warn_bytes_api()
411
{
412
    return PyErr_WarnEx(PyExc_DeprecationWarning,
413
        "The Windows bytes API has been deprecated, "
414
        "use Unicode filenames instead",
415
        1);
416
}
417
#endif
418

419

420
#ifndef MS_WINDOWS
421
PyObject *
422
_PyLong_FromUid(uid_t uid)
423
{
424
    if (uid == (uid_t)-1)
425
        return PyLong_FromLong(-1);
inline
               
PyLong_FromLong will not be inlined into _PyLong_FromUid because its definition is unavailable 
_PyLong_FromUid
426
    return PyLong_FromUnsignedLong(uid);
inline
           
PyLong_FromUnsignedLong will not be inlined into _PyLong_FromUid because its definition is unavailable 
_PyLong_FromUid
427
}
428

429
PyObject *
430
_PyLong_FromGid(gid_t gid)
431
{
432
    if (gid == (gid_t)-1)
433
        return PyLong_FromLong(-1);
inline
               
PyLong_FromLong will not be inlined into _PyLong_FromGid because its definition is unavailable 
_PyLong_FromGid
434
    return PyLong_FromUnsignedLong(gid);
inline
           
PyLong_FromUnsignedLong will not be inlined into _PyLong_FromGid because its definition is unavailable 
_PyLong_FromGid
435
}
436

437
int
438
_Py_Uid_Converter(PyObject *obj, void *p)
439
{
440
    uid_t uid;
441
    PyObject *index;
442
    int overflow;
443
    long result;
444
    unsigned long uresult;
445

446
    index = PyNumber_Index(obj);
inline
            
PyNumber_Index will not be inlined into _Py_Uid_Converter because its definition is unavailable 
_Py_Uid_Converter
447
    if (index == NULL) {
448
        PyErr_Format(PyExc_TypeError,
inline
        
PyErr_Format will not be inlined into _Py_Uid_Converter because its definition is unavailable 
_Py_Uid_Converter
gvn
                     
load of type %struct._object* not eliminated because it is clobbered by call 
_Py_Uid_Converter
449
                     "uid should be integer, not %.200s",
450
                     Py_TYPE(obj)->tp_name);
gvn
                     
load of type %struct._typeobject* not eliminated because it is clobbered by call 
_Py_Uid_Converter
451
        return 0;
452
    }
453

454
    /*
455
     * Handling uid_t is complicated for two reasons:
456
     *  * Although uid_t is (always?) unsigned, it still
457
     *    accepts -1.
458
     *  * We don't know its size in advance--it may be
459
     *    bigger than an int, or it may be smaller than
460
     *    a long.
461
     *
462
     * So a bit of defensive programming is in order.
463
     * Start with interpreting the value passed
464
     * in as a signed long and see if it works.
465
     */
466

467
    result = PyLong_AsLongAndOverflow(index, &overflow);
inline
             
PyLong_AsLongAndOverflow will not be inlined into _Py_Uid_Converter because its definition is unavailable 
_Py_Uid_Converter
468

469
    if (!overflow) {
gvn
         
load of type i32 not eliminated because it is clobbered by call 
_Py_Uid_Converter
470
        uid = (uid_t)result;
471

472
        if (result == -1) {
473
            if (PyErr_Occurred())
inline
                
PyErr_Occurred will not be inlined into _Py_Uid_Converter because its definition is unavailable 
_Py_Uid_Converter
474
                goto fail;
475
            /* It's a legitimate -1, we're done. */
476
            goto success;
477
        }
478

479
        /* Any other negative number is disallowed. */
480
        if (result < 0)
481
            goto underflow;
482

483
        /* Ensure the value wasn't truncated. */
484
        if (sizeof(uid_t) < sizeof(long) &&
485
            (long)uid != result)
486
            goto underflow;
487
        goto success;
488
    }
489

490
    if (overflow < 0)
491
        goto underflow;
492

493
    /*
494
     * Okay, the value overflowed a signed long.  If it
495
     * fits in an *unsigned* long, it may still be okay,
496
     * as uid_t may be unsigned long on this platform.
497
     */
498
    uresult = PyLong_AsUnsignedLong(index);
inline
              
PyLong_AsUnsignedLong will not be inlined into _Py_Uid_Converter because its definition is unavailable 
_Py_Uid_Converter
499
    if (PyErr_Occurred()) {
inline
        
PyErr_Occurred will not be inlined into _Py_Uid_Converter because its definition is unavailable 
_Py_Uid_Converter
500
        if (PyErr_ExceptionMatches(PyExc_OverflowError))
inline
            
PyErr_ExceptionMatches will not be inlined into _Py_Uid_Converter because its definition is unavailable 
_Py_Uid_Converter
gvn
                                   
load of type %struct._object* not eliminated because it is clobbered by call 
_Py_Uid_Converter
501
            goto overflow;
502
        goto fail;
503
    }
504

505
    uid = (uid_t)uresult;
506

507
    /*
508
     * If uid == (uid_t)-1, the user actually passed in ULONG_MAX,
509
     * but this value would get interpreted as (uid_t)-1  by chown
510
     * and its siblings.   That's not what the user meant!  So we
511
     * throw an overflow exception instead.   (We already
512
     * handled a real -1 with PyLong_AsLongAndOverflow() above.)
513
     */
514
    if (uid == (uid_t)-1)
515
        goto overflow;
516

517
    /* Ensure the value wasn't truncated. */
518
    if (sizeof(uid_t) < sizeof(long) &&
519
        (unsigned long)uid != uresult)
520
        goto overflow;
521
    /* fallthrough */
522

523
success:
524
    Py_DECREF(index);
gvn
    
load of type i64 not eliminated because it is clobbered by call 
_Py_Uid_Converter
525
    *(uid_t *)p = uid;
526
    return 1;
527

528
underflow:
529
    PyErr_SetString(PyExc_OverflowError,
inline
    
PyErr_SetString will not be inlined into _Py_Uid_Converter because its definition is unavailable 
_Py_Uid_Converter
gvn
                    
load of type %struct._object* not eliminated because it is clobbered by call 
_Py_Uid_Converter
530
                    "uid is less than minimum");
531
    goto fail;
532

533
overflow:
534
    PyErr_SetString(PyExc_OverflowError,
inline
    
PyErr_SetString will not be inlined into _Py_Uid_Converter because its definition is unavailable 
_Py_Uid_Converter
gvn
                    
load of type %struct._object* not eliminated because it is clobbered by call 
_Py_Uid_Converter
535
                    "uid is greater than maximum");
536
    /* fallthrough */
537

538
fail:
539
    Py_DECREF(index);
gvn
    
load of type i64 not eliminated because it is clobbered by call 
_Py_Uid_Converter
540
    return 0;
541
}
542

543
int
544
_Py_Gid_Converter(PyObject *obj, void *p)
545
{
546
    gid_t gid;
547
    PyObject *index;
548
    int overflow;
549
    long result;
550
    unsigned long uresult;
551

552
    index = PyNumber_Index(obj);
inline
            
PyNumber_Index will not be inlined into _Py_Gid_Converter because its definition is unavailable 
_Py_Gid_Converter
553
    if (index == NULL) {
554
        PyErr_Format(PyExc_TypeError,
inline
        
PyErr_Format will not be inlined into _Py_Gid_Converter because its definition is unavailable 
_Py_Gid_Converter
gvn
                     
load of type %struct._object* not eliminated because it is clobbered by call 
_Py_Gid_Converter
555
                     "gid should be integer, not %.200s",
556
                     Py_TYPE(obj)->tp_name);
gvn
                     
load of type %struct._typeobject* not eliminated because it is clobbered by call 
_Py_Gid_Converter
557
        return 0;
558
    }
559

560
    /*
561
     * Handling gid_t is complicated for two reasons:
562
     *  * Although gid_t is (always?) unsigned, it still
563
     *    accepts -1.
564
     *  * We don't know its size in advance--it may be
565
     *    bigger than an int, or it may be smaller than
566
     *    a long.
567
     *
568
     * So a bit of defensive programming is in order.
569
     * Start with interpreting the value passed
570
     * in as a signed long and see if it works.
571
     */
572

573
    result = PyLong_AsLongAndOverflow(index, &overflow);
inline
             
PyLong_AsLongAndOverflow will not be inlined into _Py_Gid_Converter because its definition is unavailable 
_Py_Gid_Converter
574

575
    if (!overflow) {
gvn
         
load of type i32 not eliminated because it is clobbered by call 
_Py_Gid_Converter
576
        gid = (gid_t)result;
577

578
        if (result == -1) {
579
            if (PyErr_Occurred())
inline
                
PyErr_Occurred will not be inlined into _Py_Gid_Converter because its definition is unavailable 
_Py_Gid_Converter
580
                goto fail;
581
            /* It's a legitimate -1, we're done. */
582
            goto success;
583
        }
584

585
        /* Any other negative number is disallowed. */
586
        if (result < 0) {
587
            goto underflow;
588
        }
589

590
        /* Ensure the value wasn't truncated. */
591
        if (sizeof(gid_t) < sizeof(long) &&
592
            (long)gid != result)
593
            goto underflow;
594
        goto success;
595
    }
596

597
    if (overflow < 0)
598
        goto underflow;
599

600
    /*
601
     * Okay, the value overflowed a signed long.  If it
602
     * fits in an *unsigned* long, it may still be okay,
603
     * as gid_t may be unsigned long on this platform.
604
     */
605
    uresult = PyLong_AsUnsignedLong(index);
inline
              
PyLong_AsUnsignedLong will not be inlined into _Py_Gid_Converter because its definition is unavailable 
_Py_Gid_Converter
606
    if (PyErr_Occurred()) {
inline
        
PyErr_Occurred will not be inlined into _Py_Gid_Converter because its definition is unavailable 
_Py_Gid_Converter
607
        if (PyErr_ExceptionMatches(PyExc_OverflowError))
inline
            
PyErr_ExceptionMatches will not be inlined into _Py_Gid_Converter because its definition is unavailable 
_Py_Gid_Converter
gvn
                                   
load of type %struct._object* not eliminated because it is clobbered by call 
_Py_Gid_Converter
608
            goto overflow;
609
        goto fail;
610
    }
611

612
    gid = (gid_t)uresult;
613

614
    /*
615
     * If gid == (gid_t)-1, the user actually passed in ULONG_MAX,
616
     * but this value would get interpreted as (gid_t)-1  by chown
617
     * and its siblings.   That's not what the user meant!  So we
618
     * throw an overflow exception instead.   (We already
619
     * handled a real -1 with PyLong_AsLongAndOverflow() above.)
620
     */
621
    if (gid == (gid_t)-1)
622
        goto overflow;
623

624
    /* Ensure the value wasn't truncated. */
625
    if (sizeof(gid_t) < sizeof(long) &&
626
        (unsigned long)gid != uresult)
627
        goto overflow;
628
    /* fallthrough */
629

630
success:
631
    Py_DECREF(index);
gvn
    
load of type i64 not eliminated because it is clobbered by call 
_Py_Gid_Converter
632
    *(gid_t *)p = gid;
633
    return 1;
634

635
underflow:
636
    PyErr_SetString(PyExc_OverflowError,
inline
    
PyErr_SetString will not be inlined into _Py_Gid_Converter because its definition is unavailable 
_Py_Gid_Converter
gvn
                    
load of type %struct._object* not eliminated because it is clobbered by call 
_Py_Gid_Converter
637
                    "gid is less than minimum");
638
    goto fail;
639

640
overflow:
641
    PyErr_SetString(PyExc_OverflowError,
inline
    
PyErr_SetString will not be inlined into _Py_Gid_Converter because its definition is unavailable 
_Py_Gid_Converter
gvn
                    
load of type %struct._object* not eliminated because it is clobbered by call 
_Py_Gid_Converter
642
                    "gid is greater than maximum");
643
    /* fallthrough */
644

645
fail:
646
    Py_DECREF(index);
gvn
    
load of type i64 not eliminated because it is clobbered by call 
_Py_Gid_Converter
647
    return 0;
648
}
649
#endif /* MS_WINDOWS */
650

651

652
#define _PyLong_FromDev PyLong_FromLongLong
653

654

655
#if defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)
656
static int
657
_Py_Dev_Converter(PyObject *obj, void *p)
658
{
659
    *((dev_t *)p) = PyLong_AsUnsignedLongLong(obj);
inline
                    
PyLong_AsUnsignedLongLong will not be inlined into _Py_Dev_Converter because its definition is unavailable 
_Py_Dev_Converter
660
    if (PyErr_Occurred())
inline
        
PyErr_Occurred will not be inlined into _Py_Dev_Converter because its definition is unavailable 
_Py_Dev_Converter
661
        return 0;
662
    return 1;
663
}
664
#endif /* HAVE_MKNOD && HAVE_MAKEDEV */
665

666

667
#ifdef AT_FDCWD
668
/*
669
 * Why the (int) cast?  Solaris 10 defines AT_FDCWD as 0xffd19553 (-3041965);
670
 * without the int cast, the value gets interpreted as uint (4291925331),
671
 * which doesn't play nicely with all the initializer lines in this file that
672
 * look like this:
673
 *      int dir_fd = DEFAULT_DIR_FD;
674
 */
675
#define DEFAULT_DIR_FD (int)AT_FDCWD
676
#else
677
#define DEFAULT_DIR_FD (-100)
678
#endif
679

680
static int
681
_fd_converter(PyObject *o, int *p)
682
{
683
    int overflow;
684
    long long_value;
685

686
    PyObject *index = PyNumber_Index(o);
inline
                      
PyNumber_Index will not be inlined into _fd_converter because its definition is unavailable 
_fd_converter
687
    if (index == NULL) {
688
        return 0;
689
    }
690

691
    assert(PyLong_Check(index));
692
    long_value = PyLong_AsLongAndOverflow(index, &overflow);
inline
                 
PyLong_AsLongAndOverflow will not be inlined into _fd_converter because its definition is unavailable 
_fd_converter
693
    Py_DECREF(index);
gvn
    
load of type i64 not eliminated because it is clobbered by call 
_fd_converter
gvn
    
load of type i64 not eliminated because it is clobbered by call 
dir_fd_converter
gvn
    
load of type i64 not eliminated because it is clobbered by call 
path_converter
694
    assert(!PyErr_Occurred());
695
    if (overflow > 0 || long_value > INT_MAX) {
gvn
        
load of type i32 not eliminated because it is clobbered by call 
_fd_converter
gvn
        
load of type i32 not eliminated because it is clobbered by call 
dir_fd_converter
gvn
        
load of type i32 not eliminated because it is clobbered by call 
path_converter
696
        PyErr_SetString(PyExc_OverflowError,
inline
        
PyErr_SetString will not be inlined into _fd_converter because its definition is unavailable 
_fd_converter
gvn
                        
load of type %struct._object* not eliminated because it is clobbered by call 
_fd_converter
gvn
                        
load of type %struct._object* not eliminated because it is clobbered by call 
dir_fd_converter
gvn
                        
load of type %struct._object* not eliminated because it is clobbered by call 
path_converter
697
                        "fd is greater than maximum");
698
        return 0;
699
    }
700
    if (overflow < 0 || long_value < INT_MIN) {
701
        PyErr_SetString(PyExc_OverflowError,
inline
        
PyErr_SetString will not be inlined into _fd_converter because its definition is unavailable 
_fd_converter
gvn
                        
load of type %struct._object* not eliminated because it is clobbered by call 
_fd_converter
gvn
                        
load of type %struct._object* not eliminated because it is clobbered by call 
dir_fd_converter
gvn
                        
load of type %struct._object* not eliminated because it is clobbered by call 
path_converter
702
                        "fd is less than minimum");
703
        return 0;
704
    }
705

706
    *p = (int)long_value;
707
    return 1;
708
}
709

710
static int
711
dir_fd_converter(PyObject *o, void *p)
712
{
713
    if (o == Py_None) {
714
        *(int *)p = DEFAULT_DIR_FD;
715
        return 1;
716
    }
717
    else if (PyIndex_Check(o)) {
718
        return _fd_converter(o, (int *)p);
inline
               
_fd_converter can be inlined into dir_fd_converter with cost=235 (threshold=250) 
dir_fd_converter
inline
               
_fd_converter inlined into dir_fd_converter 
dir_fd_converter
719
    }
720
    else {
721
        PyErr_Format(PyExc_TypeError,
inline
        
PyErr_Format will not be inlined into dir_fd_converter because its definition is unavailable 
dir_fd_converter
722
                     "argument should be integer or None, not %.200s",
723
                     Py_TYPE(o)->tp_name);
724
        return 0;
725
    }
726
}
727

728

729
/*
730
 * A PyArg_ParseTuple "converter" function
731
 * that handles filesystem paths in the manner
732
 * preferred by the os module.
733
 *
734
 * path_converter accepts (Unicode) strings and their
735
 * subclasses, and bytes and their subclasses.  What
736
 * it does with the argument depends on the platform:
737
 *
738
 *   * On Windows, if we get a (Unicode) string we
739
 *     extract the wchar_t * and return it; if we get
740
 *     bytes we decode to wchar_t * and return that.
741
 *
742
 *   * On all other platforms, strings are encoded
743
 *     to bytes using PyUnicode_FSConverter, then we
744
 *     extract the char * from the bytes object and
745
 *     return that.
746
 *
747
 * path_converter also optionally accepts signed
748
 * integers (representing open file descriptors) instead
749
 * of path strings.
750
 *
751
 * Input fields:
752
 *   path.nullable
753
 *     If nonzero, the path is permitted to be None.
754
 *   path.allow_fd
755
 *     If nonzero, the path is permitted to be a file handle
756
 *     (a signed int) instead of a string.
757
 *   path.function_name
758
 *     If non-NULL, path_converter will use that as the name
759
 *     of the function in error messages.
760
 *     (If path.function_name is NULL it omits the function name.)
761
 *   path.argument_name
762
 *     If non-NULL, path_converter will use that as the name
763
 *     of the parameter in error messages.
764
 *     (If path.argument_name is NULL it uses "path".)
765
 *
766
 * Output fields:
767
 *   path.wide
768
 *     Points to the path if it was expressed as Unicode
769
 *     and was not encoded.  (Only used on Windows.)
770
 *   path.narrow
771
 *     Points to the path if it was expressed as bytes,
772
 *     or it was Unicode and was encoded to bytes. (On Windows,
773
 *     is a non-zero integer if the path was expressed as bytes.
774
 *     The type is deliberately incompatible to prevent misuse.)
775
 *   path.fd
776
 *     Contains a file descriptor if path.accept_fd was true
777
 *     and the caller provided a signed integer instead of any
778
 *     sort of string.
779
 *
780
 *     WARNING: if your "path" parameter is optional, and is
781
 *     unspecified, path_converter will never get called.
782
 *     So if you set allow_fd, you *MUST* initialize path.fd = -1
783
 *     yourself!
784
 *   path.length
785
 *     The length of the path in characters, if specified as
786
 *     a string.
787
 *   path.object
788
 *     The original object passed in.
789
 *   path.cleanup
790
 *     For internal use only.  May point to a temporary object.
791
 *     (Pay no attention to the man behind the curtain.)
792
 *
793
 *   At most one of path.wide or path.narrow will be non-NULL.
794
 *   If path was None and path.nullable was set,
795
 *     or if path was an integer and path.allow_fd was set,
796
 *     both path.wide and path.narrow will be NULL
797
 *     and path.length will be 0.
798
 *
799
 *   path_converter takes care to not write to the path_t
800
 *   unless it's successful.  However it must reset the
801
 *   "cleanup" field each time it's called.
802
 *
803
 * Use as follows:
804
 *      path_t path;
805
 *      memset(&path, 0, sizeof(path));
806
 *      PyArg_ParseTuple(args, "O&", path_converter, &path);
807
 *      // ... use values from path ...
808
 *      path_cleanup(&path);
809
 *
810
 * (Note that if PyArg_Parse fails you don't need to call
811
 * path_cleanup().  However it is safe to do so.)
812
 */
813
typedef struct {
814
    const char *function_name;
815
    const char *argument_name;
816
    int nullable;
817
    int allow_fd;
818
    const wchar_t *wide;
819
#ifdef MS_WINDOWS
820
    BOOL narrow;
821
#else
822
    const char *narrow;
823
#endif
824
    int fd;
825
    Py_ssize_t length;
826
    PyObject *object;
827
    PyObject *cleanup;
828
} path_t;
829

830
#ifdef MS_WINDOWS
831
#define PATH_T_INITIALIZE(function_name, argument_name, nullable, allow_fd) \
832
    {function_name, argument_name, nullable, allow_fd, NULL, FALSE, -1, 0, NULL, NULL}
833
#else
834
#define PATH_T_INITIALIZE(function_name, argument_name, nullable, allow_fd) \
835
    {function_name, argument_name, nullable, allow_fd, NULL, NULL, -1, 0, NULL, NULL}
836
#endif
837

838
static void
839
path_cleanup(path_t *path) {
840
    if (path->cleanup) {
gvn
              
load of type %struct._object* not eliminated because it is clobbered by call 
os_stat
gvn
              
load of type %struct._object* not eliminated because it is clobbered by call 
os_access
gvn
              
load of type %struct._object* not eliminated because it is clobbered by call 
os_chdir
gvn
              
load of type %struct._object* not eliminated because it is clobbered by call 
os_chmod
gvn
              
load of type %struct._object* not eliminated because it is clobbered by call 
os_chown
gvn
              
load of type %struct._object* not eliminated because it is clobbered by call 
os_lchown
gvn
              
load of type %struct._object* not eliminated because it is clobbered by call 
os_chroot
gvn
              
load of type %struct._object* not eliminated because it is clobbered by call 
os_link
gvn
              
load of type %struct._object* not eliminated because it is clobbered by call 
os_listdir
gvn
              
load of type %struct._object* not eliminated because it is clobbered by call 
os_lstat
gvn
              
load of type %struct._object* not eliminated because it is clobbered by call 
os_mkdir
gvn
              
load of type %struct._object* not eliminated because it is clobbered by call 
posix_readlink
gvn
              
load of type %struct._object* not eliminated because it is clobbered by call 
os_rename
gvn
              
load of type %struct._object* not eliminated because it is clobbered by call 
os_replace
gvn
              
load of type %struct._object* not eliminated because it is clobbered by call 
os_rmdir
gvn
              
load of type %struct._object* not eliminated because it is clobbered by call 
os_symlink
gvn
              
load of type %struct._object* not eliminated because it is clobbered by call 
os_unlink
gvn
              
load of type %struct._object* not eliminated because it is clobbered by call 
os_remove
gvn
              
load of type %struct._object* not eliminated because it is clobbered by call 
os_utime
gvn
              
load of type %struct._object* not eliminated because it is clobbered by call 
os_execv
gvn
              
load of type %struct._object* not eliminated because it is clobbered by call 
os_execve
gvn
              
load of type %struct._object* not eliminated because it is clobbered by call 
os_open
gvn
              
load of type %struct._object* not eliminated because it is clobbered by call 
os_mkfifo
gvn
              
load of type %struct._object* not eliminated because it is clobbered by call 
os_mknod
gvn
              
load of type %struct._object* not eliminated because it is clobbered by call 
os_truncate
gvn
              
load of type %struct._object* not eliminated because it is clobbered by call 
os_statvfs
gvn
              
load of type %struct._object* not eliminated because it is clobbered by call 
os_pathconf
gvn
              
load of type %struct._object* not eliminated because it is clobbered by call 
os_getxattr
gvn
              
load of type %struct._object* not eliminated because it is clobbered by call 
os_setxattr
gvn
              
load of type %struct._object* not eliminated because it is clobbered by call 
os_removexattr
gvn
              
load of type %struct._object* not eliminated because it is clobbered by call 
os_listxattr
gvn
              
load of type %struct._object* not eliminated because it is clobbered by call 
ScandirIterator_finalize
841
        Py_CLEAR(path->cleanup);
842
    }
843
}
844

845
static int
846
path_converter(PyObject *o, void *p)
847
{
848
    path_t *path = (path_t *)p;
849
    PyObject *bytes, *to_cleanup = NULL;
850
    Py_ssize_t length;
851
    int is_index, is_buffer, is_bytes, is_unicode;
852
    /* Default to failure, forcing explicit signaling of succcess. */
853
    int ret = 0;
854
    const char *narrow;
855
#ifdef MS_WINDOWS
856
    PyObject *wo;
857
    const wchar_t *wide;
858
#endif
859

860
#define FORMAT_EXCEPTION(exc, fmt) \
861
    PyErr_Format(exc, "%s%s" fmt, \
862
        path->function_name ? path->function_name : "", \
863
        path->function_name ? ": "                : "", \
864
        path->argument_name ? path->argument_name : "path")
865

866
    /* Py_CLEANUP_SUPPORTED support */
867
    if (o == NULL) {
868
        path_cleanup(path);
inline
        
path_cleanup can be inlined into path_converter with cost=30 (threshold=250) 
path_converter
inline
        
path_cleanup inlined into path_converter 
path_converter
869
        return 1;
870
    }
871

872
    /* Ensure it's always safe to call path_cleanup(). */
873
    path->cleanup = NULL;
874

875
    if ((o == Py_None) && path->nullable) {
876
        path->wide = NULL;
877
#ifdef MS_WINDOWS
878
        path->narrow = FALSE;
879
#else
880
        path->narrow = NULL;
881
#endif
882
        path->length = 0;
883
        path->object = o;
884
        path->fd = -1;
885
        return 1;
886
    }
887

888
    /* Only call this here so that we don't treat the return value of
889
       os.fspath() as an fd or buffer. */
890
    is_index = path->allow_fd && PyIndex_Check(o);
891
    is_buffer = PyObject_CheckBuffer(o);
892
    is_bytes = PyBytes_Check(o);
gvn
               
load of type %struct._typeobject* eliminated in favor of load 
path_converter
893
    is_unicode = PyUnicode_Check(o);
894

895
    if (!is_index && !is_buffer && !is_unicode && !is_bytes) {
896
        /* Inline PyOS_FSPath() for better error messages. */
897
        _Py_IDENTIFIER(__fspath__);
898
        PyObject *func = NULL;
899

900
        func = _PyObject_LookupSpecial(o, &PyId___fspath__);
inline
               
_PyObject_LookupSpecial will not be inlined into path_converter because its definition is unavailable 
path_converter
901
        if (NULL == func) {
902
            goto error_exit;
903
        }
904

905
        o = to_cleanup = PyObject_CallFunctionObjArgs(func, NULL);
inline
                         
PyObject_CallFunctionObjArgs will not be inlined into path_converter because its definition is unavailable 
path_converter
906
        Py_DECREF(func);
gvn
        
load of type i64 not eliminated because it is clobbered by call 
path_converter
907
        if (NULL == o) {
908
            goto error_exit;
909
        }
910
        else if (PyUnicode_Check(o)) {
gvn
                 
load of type %struct._typeobject* not eliminated because it is clobbered by call 
path_converter
911
            is_unicode = 1;
912
        }
913
        else if (PyBytes_Check(o)) {
914
            is_bytes = 1;
915
        }
916
        else {
917
            goto error_exit;
918
        }
919
    }
920

921
    if (is_unicode) {
922
#ifdef MS_WINDOWS
923
        wide = PyUnicode_AsUnicodeAndSize(o, &length);
924
        if (!wide) {
925
            goto exit;
926
        }
927
        if (length > 32767) {
928
            FORMAT_EXCEPTION(PyExc_ValueError, "%s too long for Windows");
929
            goto exit;
930
        }
931
        if (wcslen(wide) != length) {
932
            FORMAT_EXCEPTION(PyExc_ValueError, "embedded null character in %s");
933
            goto exit;
934
        }
935

936
        path->wide = wide;
937
        path->length = length;
938
        path->object = o;
939
        path->fd = -1;
940
        ret = 1;
941
        goto exit;
942
#else
943
        if (!PyUnicode_FSConverter(o, &bytes)) {
inline
             
PyUnicode_FSConverter will not be inlined into path_converter because its definition is unavailable 
path_converter
944
            goto exit;
945
        }
946
#endif
947
    }
948
    else if (is_bytes) {
949
        bytes = o;
950
        Py_INCREF(bytes);
951
    }
952
    else if (is_buffer) {
953
        if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1,
inline
            
PyErr_WarnFormat will not be inlined into path_converter because its definition is unavailable 
path_converter
gvn
                             
load of type %struct._object* not eliminated because it is clobbered by call 
path_converter
954
            "%s%s%s should be %s, not %.200s",
955
            path->function_name ? path->function_name : "",
gvn
                  
load of type i8* not eliminated because it is clobbered by call 
path_converter
956
            path->function_name ? ": "                : "",
957
            path->argument_name ? path->argument_name : "path",
gvn
                  
load of type i8* not eliminated because it is clobbered by call 
path_converter
958
            path->allow_fd && path->nullable ? "string, bytes, os.PathLike, "
gvn
                  
load of type i32 not eliminated in favor of load because it is clobbered by call 
path_converter
959
                                               "integer or None" :
960
            path->allow_fd ? "string, bytes, os.PathLike or integer" :
961
            path->nullable ? "string, bytes, os.PathLike or None" :
962
                             "string, bytes or os.PathLike",
963
            Py_TYPE(o)->tp_name)) {
gvn
            
load of type %struct._typeobject* eliminated in favor of phi 
path_converter
964
            goto exit;
965
        }
966
        bytes = PyBytes_FromObject(o);
inline
                
PyBytes_FromObject will not be inlined into path_converter because its definition is unavailable 
path_converter
967
        if (!bytes) {
968
            goto exit;
969
        }
970
    }
971
    else if (is_index) {
972
        if (!_fd_converter(o, &path->fd)) {
inline
             
_fd_converter can be inlined into path_converter with cost=-14765 (threshold=250) 
path_converter
inline
             
_fd_converter inlined into path_converter 
path_converter
973
            goto exit;
974
        }
975
        path->wide = NULL;
976
#ifdef MS_WINDOWS
977
        path->narrow = FALSE;
978
#else
979
        path->narrow = NULL;
980
#endif
981
        path->length = 0;
982
        path->object = o;
983
        ret = 1;
984
        goto exit;
985
    }
986
    else {
987
 error_exit:
988
        PyErr_Format(PyExc_TypeError, "%s%s%s should be %s, not %.200s",
inline
        
PyErr_Format will not be inlined into path_converter because its definition is unavailable 
path_converter
gvn
                     
load of type %struct._object* not eliminated because it is clobbered by call 
path_converter
989
            path->function_name ? path->function_name : "",
gvn
                  
load of type i8* not eliminated because it is clobbered by call 
path_converter
990
            path->function_name ? ": "                : "",
991
            path->argument_name ? path->argument_name : "path",
gvn
                  
load of type i8* not eliminated because it is clobbered by call 
path_converter
992
            path->allow_fd && path->nullable ? "string, bytes, os.PathLike, "
gvn
                  
load of type i32 not eliminated in favor of load because it is clobbered by call 
path_converter
993
                                               "integer or None" :
994
            path->allow_fd ? "string, bytes, os.PathLike or integer" :
995
            path->nullable ? "string, bytes, os.PathLike or None" :
996
                             "string, bytes or os.PathLike",
997
            Py_TYPE(o)->tp_name);
gvn
            
load of type %struct._typeobject* not eliminated because it is clobbered by call 
path_converter
gvn
            
load eliminated by PRE 
path_converter
998
        goto exit;
999
    }
1000

1001
    length = PyBytes_GET_SIZE(bytes);
gvn
             
load of type %struct._object* not eliminated because it is clobbered by call 
path_converter
gvn
             
load eliminated by PRE 
path_converter
1002
    narrow = PyBytes_AS_STRING(bytes);
1003
    if ((size_t)length != strlen(narrow)) {
inline
                          
strlen will not be inlined into path_converter because its definition is unavailable 
path_converter
1004
        FORMAT_EXCEPTION(PyExc_ValueError, "embedded null character in %s");
inline
        
PyErr_Format will not be inlined into path_converter because its definition is unavailable 
path_converter
gvn
        
load of type %struct._object* not eliminated because it is clobbered by call 
path_converter
1005
        Py_DECREF(bytes);
gvn
        
load of type %struct._object* not eliminated because it is clobbered by call 
path_converter
1006
        goto exit;
1007
    }
1008

1009
#ifdef MS_WINDOWS
1010
    wo = PyUnicode_DecodeFSDefaultAndSize(
1011
        narrow,
1012
        length
1013
    );
1014
    if (!wo) {
1015
        goto exit;
1016
    }
1017

1018
    wide = PyUnicode_AsWideCharString(wo, &length);
1019
    Py_DECREF(wo);
1020

1021
    if (!wide) {
1022
        goto exit;
1023
    }
1024
    if (length > 32767) {
1025
        FORMAT_EXCEPTION(PyExc_ValueError, "%s too long for Windows");
1026
        goto exit;
1027
    }
1028
    if (wcslen(wide) != length) {
1029
        FORMAT_EXCEPTION(PyExc_ValueError, "embedded null character in %s");
1030
        goto exit;
1031
    }
1032
    path->wide = wide;
1033
    path->narrow = TRUE;
1034
#else
1035
    path->wide = NULL;
1036
    path->narrow = narrow;
1037
#endif
1038
    path->length = length;
1039
    path->object = o;
1040
    path->fd = -1;
1041
    if (bytes == o) {
1042
        Py_DECREF(bytes);
gvn
        
load of type i64 not eliminated because it is clobbered by call 
path_converter
1043
        ret = 1;
1044
    }
1045
    else {
1046
        path->cleanup = bytes;
1047
        ret = Py_CLEANUP_SUPPORTED;
1048
    }
1049
 exit:
1050
    Py_XDECREF(to_cleanup);
1051
    return ret;
1052
}
1053

1054
static void
1055
argument_unavailable_error(const char *function_name, const char *argument_name)
1056
{
1057
    PyErr_Format(PyExc_NotImplementedError,
inline
    
PyErr_Format will not be inlined into argument_unavailable_error because its definition is unavailable 
argument_unavailable_error
gvn
                 
load of type %struct._object* not eliminated because it is clobbered by call 
os_chmod_impl
gvn
                 
load of type %struct._object* not eliminated because it is clobbered by call 
os_chmod
1058
        "%s%s%s unavailable on this platform",
1059
        (function_name != NULL) ? function_name : "",
1060
        (function_name != NULL) ? ": ": "",
1061
        argument_name);
1062
}
1063

1064
static int
1065
dir_fd_unavailable(PyObject *o, void *p)
1066
{
1067
    int dir_fd;
1068
    if (!dir_fd_converter(o, &dir_fd))
inline
         
dir_fd_converter can be inlined into dir_fd_unavailable with cost=-35 (threshold=375) 
dir_fd_unavailable
inline
         
dir_fd_converter inlined into dir_fd_unavailable 
dir_fd_unavailable
1069
        return 0;
1070
    if (dir_fd != DEFAULT_DIR_FD) {
1071
        argument_unavailable_error(NULL, "dir_fd");
inline
        
argument_unavailable_error can be inlined into dir_fd_unavailable with cost=-14970 (threshold=375) 
dir_fd_unavailable
inline
        
argument_unavailable_error inlined into dir_fd_unavailable 
dir_fd_unavailable
1072
        return 0;
1073
    }
1074
    *(int *)p = dir_fd;
1075
    return 1;
1076
}
1077

1078
static int
1079
fd_specified(const char *function_name, int fd)
1080
{
1081
    if (fd == -1)
1082
        return 0;
1083

1084
    argument_unavailable_error(function_name, "fd");
1085
    return 1;
1086
}
1087

1088
static int
1089
follow_symlinks_specified(const char *function_name, int follow_symlinks)
1090
{
1091
    if (follow_symlinks)
1092
        return 0;
1093

1094
    argument_unavailable_error(function_name, "follow_symlinks");
inline
    
argument_unavailable_error can be inlined into follow_symlinks_specified with cost=35 (threshold=375) 
follow_symlinks_specified
inline
    
argument_unavailable_error inlined into follow_symlinks_specified 
follow_symlinks_specified
1095
    return 1;
1096
}
1097

1098
static int
1099
path_and_dir_fd_invalid(const char *function_name, path_t *path, int dir_fd)
1100
{
1101
    if (!path->wide && (dir_fd != DEFAULT_DIR_FD)
gvn
               
load of type i32* not eliminated because it is clobbered by call 
os_utime_impl
gvn
               
load of type i32* not eliminated because it is clobbered by call 
os_utime
1102
#ifndef MS_WINDOWS
1103
        && !path->narrow
gvn
                  
load of type i8* not eliminated because it is clobbered by call 
os_utime_impl
gvn
                  
load of type i8* not eliminated because it is clobbered by call 
os_utime
1104
#endif
1105
    ) {
1106
        PyErr_Format(PyExc_ValueError,
inline
        
PyErr_Format will not be inlined into path_and_dir_fd_invalid because its definition is unavailable 
path_and_dir_fd_invalid
gvn
                     
load of type %struct._object* not eliminated because it is clobbered by call 
os_utime_impl
gvn
                     
load of type %struct._object* not eliminated because it is clobbered by call 
os_utime
1107
                     "%s: can't specify dir_fd without matching path",
1108
                     function_name);
1109
        return 1;
1110
    }
1111
    return 0;
1112
}
1113

1114
static int
1115
dir_fd_and_fd_invalid(const char *function_name, int dir_fd, int fd)
1116
{
1117
    if ((dir_fd != DEFAULT_DIR_FD) && (fd != -1)) {
1118
        PyErr_Format(PyExc_ValueError,
inline
        
PyErr_Format will not be inlined into dir_fd_and_fd_invalid because its definition is unavailable 
dir_fd_and_fd_invalid
gvn
                     
load of type %struct._object* not eliminated because it is clobbered by call 
os_chown
gvn
                     
load of type %struct._object* not eliminated because it is clobbered by call 
os_utime_impl
gvn
                     
load of type %struct._object* not eliminated because it is clobbered by call 
os_utime
1119
                     "%s: can't specify both dir_fd and fd",
1120
                     function_name);
1121
        return 1;
1122
    }
1123
    return 0;
1124
}
1125

1126
static int
1127
fd_and_follow_symlinks_invalid(const char *function_name, int fd,
1128
                               int follow_symlinks)
1129
{
1130
    if ((fd > 0) && (!follow_symlinks)) {
1131
        PyErr_Format(PyExc_ValueError,
inline
        
PyErr_Format will not be inlined into fd_and_follow_symlinks_invalid because its definition is unavailable 
fd_and_follow_symlinks_invalid
gvn
                     
load of type %struct._object* not eliminated because it is clobbered by call 
os_chown
gvn
                     
load of type %struct._object* not eliminated because it is clobbered by call 
os_utime_impl
gvn
                     
load of type %struct._object* not eliminated because it is clobbered by call 
os_utime
gvn
                     
load of type %struct._object* not eliminated because it is clobbered by call 
os_getxattr
gvn
                     
load of type %struct._object* not eliminated because it is clobbered by call 
os_setxattr
gvn
                     
load of type %struct._object* not eliminated because it is clobbered by call 
os_removexattr
gvn
                     
load of type %struct._object* not eliminated because it is clobbered by call 
os_listxattr
1132
                     "%s: cannot use fd and follow_symlinks together",
1133
                     function_name);
1134
        return 1;
1135
    }
1136
    return 0;
1137
}
1138

1139
static int
1140
dir_fd_and_follow_symlinks_invalid(const char *function_name, int dir_fd,
1141
                                   int follow_symlinks)
1142
{
1143
    if ((dir_fd != DEFAULT_DIR_FD) && (!follow_symlinks)) {
1144
        PyErr_Format(PyExc_ValueError,
inline
        
PyErr_Format will not be inlined into dir_fd_and_follow_symlinks_invalid because its definition is unavailable 
dir_fd_and_follow_symlinks_invalid
gvn
                     
load of type %struct._object* not eliminated because it is clobbered by call 
os_chmod_impl
gvn
                     
load of type %struct._object* not eliminated because it is clobbered by call 
os_chmod
1145
                     "%s: cannot use dir_fd and follow_symlinks together",
1146
                     function_name);
1147
        return 1;
1148
    }
1149
    return 0;
1150
}
1151

1152
#ifdef MS_WINDOWS
1153
    typedef long long Py_off_t;
1154
#else
1155
    typedef off_t Py_off_t;
1156
#endif
1157

1158
static int
1159
Py_off_t_converter(PyObject *arg, void *addr)
1160
{
1161
#ifdef HAVE_LARGEFILE_SUPPORT
1162
    *((Py_off_t *)addr) = PyLong_AsLongLong(arg);
1163
#else
1164
    *((Py_off_t *)addr) = PyLong_AsLong(arg);
inline
                          
PyLong_AsLong will not be inlined into Py_off_t_converter because its definition is unavailable 
Py_off_t_converter
1165
#endif
1166
    if (PyErr_Occurred())
inline
        
PyErr_Occurred will not be inlined into Py_off_t_converter because its definition is unavailable 
Py_off_t_converter
1167
        return 0;
1168
    return 1;
1169
}
1170

1171
static PyObject *
1172
PyLong_FromPy_off_t(Py_off_t offset)
1173
{
1174
#ifdef HAVE_LARGEFILE_SUPPORT
1175
    return PyLong_FromLongLong(offset);
1176
#else
1177
    return PyLong_FromLong(offset);
inline
           
PyLong_FromLong will not be inlined into PyLong_FromPy_off_t because its definition is unavailable 
PyLong_FromPy_off_t
1178
#endif
1179
}
1180

1181
#ifdef MS_WINDOWS
1182

1183
static int
1184
win32_get_reparse_tag(HANDLE reparse_point_handle, ULONG *reparse_tag)
1185
{
1186
    char target_buffer[_Py_MAXIMUM_REPARSE_DATA_BUFFER_SIZE];
1187
    _Py_REPARSE_DATA_BUFFER *rdb = (_Py_REPARSE_DATA_BUFFER *)target_buffer;
1188
    DWORD n_bytes_returned;
1189

1190
    if (0 == DeviceIoControl(
1191
        reparse_point_handle,
1192
        FSCTL_GET_REPARSE_POINT,
1193
        NULL, 0, /* in buffer */
1194
        target_buffer, sizeof(target_buffer),
1195
        &n_bytes_returned,
1196
        NULL)) /* we're not using OVERLAPPED_IO */
1197
        return FALSE;
1198

1199
    if (reparse_tag)
1200
        *reparse_tag = rdb->ReparseTag;
1201

1202
    return TRUE;
1203
}
1204

1205
#endif /* MS_WINDOWS */
1206

1207
/* Return a dictionary corresponding to the POSIX environment table */
1208
#if defined(WITH_NEXT_FRAMEWORK) || (defined(__APPLE__) && defined(Py_ENABLE_SHARED))
1209
/* On Darwin/MacOSX a shared library or framework has no access to
1210
** environ directly, we must obtain it with _NSGetEnviron(). See also
1211
** man environ(7).
1212
*/
1213
#include <crt_externs.h>
1214
static char **environ;
1215
#elif !defined(_MSC_VER) && ( !defined(__WATCOMC__) || defined(__QNX__) )
1216
extern char **environ;
1217
#endif /* !_MSC_VER */
1218

1219
static PyObject *
1220
convertenviron(void)
1221
{
1222
    PyObject *d;
1223
#ifdef MS_WINDOWS
1224
    wchar_t **e;
1225
#else
1226
    char **e;
1227
#endif
1228

1229
    d = PyDict_New();
inline
        
PyDict_New will not be inlined into convertenviron because its definition is unavailable 
convertenviron
1230
    if (d == NULL)
1231
        return NULL;
1232
#if defined(WITH_NEXT_FRAMEWORK) || (defined(__APPLE__) && defined(Py_ENABLE_SHARED))
1233
    if (environ == NULL)
1234
        environ = *_NSGetEnviron();
1235
#endif
1236
#ifdef MS_WINDOWS
1237
    /* _wenviron must be initialized in this way if the program is started
1238
       through main() instead of wmain(). */
1239
    _wgetenv(L"");
1240
    if (_wenviron == NULL)
1241
        return d;
1242
    /* This part ignores errors */
1243
    for (e = _wenviron; *e != NULL; e++) {
1244
        PyObject *k;
1245
        PyObject *v;
1246
        const wchar_t *p = wcschr(*e, L'=');
1247
        if (p == NULL)
1248
            continue;
1249
        k = PyUnicode_FromWideChar(*e, (Py_ssize_t)(p-*e));
1250
        if (k == NULL) {
1251
            PyErr_Clear();
1252
            continue;
1253
        }
1254
        v = PyUnicode_FromWideChar(p+1, wcslen(p+1));
1255
        if (v == NULL) {
1256
            PyErr_Clear();
1257
            Py_DECREF(k);
1258
            continue;
1259
        }
1260
        if (PyDict_GetItem(d, k) == NULL) {
1261
            if (PyDict_SetItem(d, k, v) != 0)
1262
                PyErr_Clear();
1263
        }
1264
        Py_DECREF(k);
1265
        Py_DECREF(v);
1266
    }
1267
#else
1268
    if (environ == NULL)
gvn
        
load of type i8** not eliminated because it is clobbered by call 
convertenviron
gvn
        
load of type i8** not eliminated because it is clobbered by call 
PyInit_posix
1269
        return d;
1270
    /* This part ignores errors */
1271
    for (e = environ; *e != NULL; e++) {
gvn
                      
load of type i8* not eliminated because it is clobbered by call 
convertenviron
gvn
                      
load of type i8* not eliminated because it is clobbered by call 
PyInit_posix
loop-vectorize
    
loop not vectorized 
PyInit_posix
1272
        PyObject *k;
1273
        PyObject *v;
1274
        const char *p = strchr(*e, '=');
inline
                        
strchr will not be inlined into convertenviron because its definition is unavailable 
convertenviron
1275
        if (p == NULL)
1276
            continue;
1277
        k = PyBytes_FromStringAndSize(*e, (int)(p-*e));
inline
            
PyBytes_FromStringAndSize will not be inlined into convertenviron because its definition is unavailable 
convertenviron
1278
        if (k == NULL) {
loop-vectorize
            
loop not vectorized: control flow cannot be substituted for a select 
PyInit_posix
1279
            PyErr_Clear();
inline
            
PyErr_Clear will not be inlined into convertenviron because its definition is unavailable 
convertenviron
1280
            continue;
1281
        }
1282
        v = PyBytes_FromStringAndSize(p+1, strlen(p+1));
inline
                                           
strlen will not be inlined into convertenviron because its definition is unavailable 
convertenviron
inline
            
PyBytes_FromStringAndSize will not be inlined into convertenviron because its definition is unavailable 
convertenviron
1283
        if (v == NULL) {
1284
            PyErr_Clear();
inline
            
PyErr_Clear will not be inlined into convertenviron because its definition is unavailable 
convertenviron
1285
            Py_DECREF(k);
gvn
            
load of type i64 not eliminated because it is clobbered by call 
convertenviron
gvn
            
load of type i64 not eliminated because it is clobbered by call 
PyInit_posix
1286
            continue;
1287
        }
1288
        if (PyDict_GetItem(d, k) == NULL) {
inline
            
PyDict_GetItem will not be inlined into convertenviron because its definition is unavailable 
convertenviron
1289
            if (PyDict_SetItem(d, k, v) != 0)
inline
                
PyDict_SetItem will not be inlined into convertenviron because its definition is unavailable 
convertenviron
1290
                PyErr_Clear();
inline
                
PyErr_Clear will not be inlined into convertenviron because its definition is unavailable 
convertenviron
1291
        }
1292
        Py_DECREF(k);
gvn
        
load of type i64 not eliminated because it is clobbered by call 
convertenviron
gvn
        
load of type i64 not eliminated because it is clobbered by call 
PyInit_posix
1293
        Py_DECREF(v);
gvn
        
load of type i64 not eliminated because it is clobbered by store 
convertenviron
gvn
        
load of type i64 not eliminated because it is clobbered by call 
PyInit_posix
1294
    }
1295
#endif
1296
    return d;
1297
}
1298

1299
/* Set a POSIX-specific error from errno, and return NULL */
1300

1301
static PyObject *
1302
posix_error(void)
1303
{
1304
    return PyErr_SetFromErrno(PyExc_OSError);
inline
           
PyErr_SetFromErrno will not be inlined into posix_error because its definition is unavailable 
posix_error
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_ttyname_impl
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_ttyname
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_fchmod_impl
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_fchmod
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_fchown_impl
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_fchown
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_ctermid_impl
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_ctermid
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
posix_getcwd
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_nice_impl
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_nice
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_getpriority_impl
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_getpriority
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_setpriority_impl
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_setpriority
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_umask_impl
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_umask
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_uname_impl
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_uname
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_utime_impl
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_utime
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_times_impl
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_times
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_execv_impl
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_execv
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_fork_impl
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_fork
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_sched_get_priority_max_impl
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_sched_get_priority_max
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_sched_get_priority_min_impl
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_sched_get_priority_min
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_sched_getparam_impl
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_sched_getparam
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_sched_getscheduler_impl
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_sched_getscheduler
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_sched_rr_get_interval_impl
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_sched_rr_get_interval
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_sched_setparam_impl
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_sched_setparam
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_sched_setscheduler_impl
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_sched_setscheduler
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_sched_yield_impl
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_sched_yield
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_sched_setaffinity_impl
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_sched_setaffinity
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_sched_getaffinity_impl
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_sched_getaffinity
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_openpty_impl
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_openpty
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_forkpty_impl
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_forkpty
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
posix_getgrouplist
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_getgroups_impl
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_getgroups
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_kill_impl
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_kill
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_killpg_impl
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_killpg
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_setuid_impl
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_setuid
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_seteuid_impl
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_seteuid
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_setreuid_impl
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_setreuid
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_setgid_impl
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_setgid
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_setegid_impl
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_setegid
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_setregid_impl
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_setregid
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_setgroups
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_getpgid_impl
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_getpgid
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_setpgrp_impl
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_setpgrp
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_wait_impl
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_wait
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_wait3_impl
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_wait3
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_wait4_impl
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_wait4
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_waitid_impl
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_waitid
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_waitpid_impl
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_waitpid
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_getsid_impl
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_getsid
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_setsid_impl
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_setsid
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_setpgid_impl
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_setpgid
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_tcgetpgrp_impl
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_tcgetpgrp
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_tcsetpgrp_impl
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_tcsetpgrp
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_close_impl
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_close
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_dup2_impl
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_dup2
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_lockf_impl
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_lockf
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_lseek_impl
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_lseek
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_read
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_readv_impl
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_readv
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_pread_impl
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_pread
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_writev_impl
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_writev
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_pwrite_impl
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_pwrite
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
posix_sendfile
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_fstat_impl
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_fstat
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_pipe2_impl
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_pipe2
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_mkfifo_impl
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_mkfifo
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_mknod_impl
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_mknod
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_ftruncate_impl
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_ftruncate
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_truncate_impl
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_truncate
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_posix_fallocate_impl
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_posix_fallocate
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_posix_fadvise_impl
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_posix_fadvise
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_putenv_impl
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_putenv
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_unsetenv_impl
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_unsetenv
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
posix_fildes_fd
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_fchdir_impl
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_fchdir
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_fsync_impl
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_fsync
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_fdatasync_impl
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_fdatasync
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_fstatvfs_impl
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_fstatvfs
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_confstr_impl
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_confstr
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_sysconf_impl
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_sysconf
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_fpathconf_impl
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_fpathconf
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_pathconf_impl
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_pathconf
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_setresuid_impl
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_setresuid
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_setresgid_impl
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_setresgid
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_getresuid_impl
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_getresuid
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_getresgid_impl
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
os_getresgid
1305
}
1306

1307
#ifdef MS_WINDOWS
1308
static PyObject *
1309
win32_error(const char* function, const char* filename)
1310
{
1311
    /* XXX We should pass the function name along in the future.
1312
       (winreg.c also wants to pass the function name.)
1313
       This would however require an additional param to the
1314
       Windows error object, which is non-trivial.
1315
    */
1316
    errno = GetLastError();
1317
    if (filename)
1318
        return PyErr_SetFromWindowsErrWithFilename(errno, filename);
1319
    else
1320
        return PyErr_SetFromWindowsErr(errno);
1321
}
1322

1323
static PyObject *
1324
win32_error_object(const char* function, PyObject* filename)
1325
{
1326
    /* XXX - see win32_error for comments on 'function' */
1327
    errno = GetLastError();
1328
    if (filename)
1329
        return PyErr_SetExcFromWindowsErrWithFilenameObject(
1330
                    PyExc_OSError,
1331
                    errno,
1332
                    filename);
1333
    else
1334
        return PyErr_SetFromWindowsErr(errno);
1335
}
1336

1337
#endif /* MS_WINDOWS */
1338

1339
static PyObject *
1340
path_object_error(PyObject *path)
1341
{
1342
#ifdef MS_WINDOWS
1343
    return PyErr_SetExcFromWindowsErrWithFilenameObject(
1344
                PyExc_OSError, 0, path);
1345
#else
1346
    return PyErr_SetFromErrnoWithFilenameObject(PyExc_OSError, path);
inline
           
PyErr_SetFromErrnoWithFilenameObject will not be inlined into path_object_error because its definition is unavailable 
path_object_error
gvn
                                                
load of type %struct._object* not eliminated because it is clobbered by call 
posix_do_stat
gvn
                                                
load of type %struct._object* not eliminated because it is clobbered by call 
os_chdir_impl
gvn
                                                
load of type %struct._object* not eliminated because it is clobbered by call 
os_chdir
gvn
                                                
load of type %struct._object* not eliminated because it is clobbered by call 
os_chmod_impl
gvn
                                                
load of type %struct._object* not eliminated because it is clobbered by call 
os_chmod
gvn
                                                
load of type %struct._object* not eliminated because it is clobbered by call 
os_chown_impl
gvn
                                                
load of type %struct._object* not eliminated because it is clobbered by call 
os_chown
gvn
                                                
load of type %struct._object* not eliminated because it is clobbered by call 
os_lchown_impl
gvn
                                                
load of type %struct._object* not eliminated because it is clobbered by call 
os_lchown
gvn
                                                
load of type %struct._object* not eliminated because it is clobbered by call 
os_chroot_impl
gvn
                                                
load of type %struct._object* not eliminated because it is clobbered by call 
os_chroot
gvn
                                                
load of type %struct._object* not eliminated because it is clobbered by call 
_posix_listdir
gvn
                                                
load of type %struct._object* not eliminated because it is clobbered by call 
os_listdir_impl
gvn
                                                
load of type %struct._object* not eliminated because it is clobbered by call 
os_listdir
gvn
                                                
load of type %struct._object* not eliminated because it is clobbered by call 
os_mkdir_impl
gvn
                                                
load of type %struct._object* not eliminated because it is clobbered by call 
os_mkdir
gvn
                                                
load of type %struct._object* not eliminated because it is clobbered by call 
posix_readlink
gvn
                                                
load of type %struct._object* not eliminated because it is clobbered by call 
os_rmdir_impl
gvn
                                                
load of type %struct._object* not eliminated because it is clobbered by call 
os_rmdir
gvn
                                                
load of type %struct._object* not eliminated because it is clobbered by call 
os_unlink_impl
gvn
                                                
load of type %struct._object* not eliminated because it is clobbered by call 
os_unlink
gvn
                                                
load of type %struct._object* not eliminated because it is clobbered by call 
os_remove_impl
gvn
                                                
load of type %struct._object* not eliminated because it is clobbered by call 
os_remove
gvn
                                                
load of type %struct._object* not eliminated because it is clobbered by call 
os_execve_impl
gvn
                                                
load of type %struct._object* not eliminated because it is clobbered by call 
os_execve
gvn
                                                
load of type %struct._object* not eliminated because it is clobbered by call 
os_truncate_impl
gvn
                                                
load of type %struct._object* not eliminated because it is clobbered by call 
os_truncate
gvn
                                                
load of type %struct._object* not eliminated because it is clobbered by call 
os_statvfs_impl
gvn
                                                
load of type %struct._object* not eliminated because it is clobbered by call 
os_statvfs
gvn
                                                
load of type %struct._object* not eliminated because it is clobbered by call 
os_pathconf_impl
gvn
                                                
load of type %struct._object* not eliminated because it is clobbered by call 
os_pathconf
gvn
                                                
load of type %struct._object* not eliminated because it is clobbered by call 
os_getxattr_impl
gvn
                                                
load of type %struct._object* not eliminated because it is clobbered by call 
os_getxattr
gvn
                                                
load of type %struct._object* not eliminated because it is clobbered by call 
os_setxattr_impl
gvn
                                                
load of type %struct._object* not eliminated because it is clobbered by call 
os_setxattr
gvn
                                                
load of type %struct._object* not eliminated because it is clobbered by call 
os_removexattr_impl
gvn
                                                
load of type %struct._object* not eliminated because it is clobbered by call 
os_removexattr
gvn
                                                
load of type %struct._object* not eliminated because it is clobbered by call 
os_listxattr_impl
gvn
                                                
load of type %struct._object* not eliminated because it is clobbered by call 
os_listxattr
gvn
                                                
load of type %struct._object* not eliminated because it is clobbered by call 
posix_scandir
gvn
                                                
load of type %struct._object* not eliminated because it is clobbered by call 
ScandirIterator_iternext
gvn
                                                
load of type %struct._object* not eliminated because it is clobbered by call 
DirEntry_fetch_stat
gvn
                                                
load of type %struct._object* not eliminated because it is clobbered by call 
DirEntry_get_lstat
gvn
                                                
load of type %struct._object* not eliminated because it is clobbered by call 
DirEntry_get_stat
1347
#endif
1348
}
1349

1350
static PyObject *
1351
path_object_error2(PyObject *path, PyObject *path2)
1352
{
1353
#ifdef MS_WINDOWS
1354
    return PyErr_SetExcFromWindowsErrWithFilenameObjects(
1355
                PyExc_OSError, 0, path, path2);
1356
#else
1357
    return PyErr_SetFromErrnoWithFilenameObjects(PyExc_OSError, path, path2);
inline
           
PyErr_SetFromErrnoWithFilenameObjects will not be inlined into path_object_error2 because its definition is unavailable 
path_object_error2
gvn
                                                 
load of type %struct._object* not eliminated because it is clobbered by call 
os_link_impl
gvn
                                                 
load of type %struct._object* not eliminated because it is clobbered by call 
os_link
gvn
                                                 
load of type %struct._object* not eliminated because it is clobbered by call 
internal_rename
gvn
                                                 
load of type %struct._object* not eliminated because it is clobbered by call 
os_symlink_impl
gvn
                                                 
load of type %struct._object* not eliminated because it is clobbered by call 
os_symlink
1358
#endif
1359
}
1360

1361
static PyObject *
1362
path_error(path_t *path)
1363
{
1364
    return path_object_error(path->object);
inline
           
path_object_error can be inlined into path_error with cost=10 (threshold=375) 
path_error
inline
           
path_object_error inlined into path_error 
path_error
1365
}
1366

1367
static PyObject *
1368
path_error2(path_t *path, path_t *path2)
1369
{
1370
    return path_object_error2(path->object, path2->object);
inline
           
path_object_error2 can be inlined into path_error2 with cost=-14990 (threshold=375) 
path_error2
inline
           
path_object_error2 inlined into path_error2 
path_error2
1371
}
1372

1373

1374
/* POSIX generic methods */
1375

1376
static int
1377
fildes_converter(PyObject *o, void *p)
1378
{
1379
    int fd;
1380
    int *pointer = (int *)p;
1381
    fd = PyObject_AsFileDescriptor(o);
inline
         
PyObject_AsFileDescriptor will not be inlined into fildes_converter because its definition is unavailable 
fildes_converter
1382
    if (fd < 0)
1383
        return 0;
1384
    *pointer = fd;
1385
    return 1;
1386
}
1387

1388
static PyObject *
1389
posix_fildes_fd(int fd, int (*func)(int))
1390
{
1391
    int res;
1392
    int async_err = 0;
1393

1394
    do {
loop-vectorize
    
loop not vectorized: loop control flow is not understood by vectorizer 
os_fchdir
loop-vectorize
    
loop not vectorized 
os_fchdir
loop-vectorize
    
loop not vectorized: loop control flow is not understood by vectorizer 
os_fsync
loop-vectorize
    
loop not vectorized 
os_fsync
loop-vectorize
    
loop not vectorized: loop control flow is not understood by vectorizer 
os_fdatasync
loop-vectorize
    
loop not vectorized 
os_fdatasync
1395
        Py_BEGIN_ALLOW_THREADS
inline
        
PyEval_SaveThread will not be inlined into posix_fildes_fd because its definition is unavailable 
posix_fildes_fd
1396
        _Py_BEGIN_SUPPRESS_IPH
1397
        res = (*func)(fd);
1398
        _Py_END_SUPPRESS_IPH
1399
        Py_END_ALLOW_THREADS
inline
        
PyEval_RestoreThread will not be inlined into posix_fildes_fd because its definition is unavailable 
posix_fildes_fd
1400
    } while (res != 0 && errno == EINTR && !(async_err = PyErr_CheckSignals()));
inline
                         
__errno_location will not be inlined into posix_fildes_fd because its definition is unavailable 
posix_fildes_fd
inline
                                                         
PyErr_CheckSignals will not be inlined into posix_fildes_fd because its definition is unavailable 
posix_fildes_fd
1401
    if (res != 0)
1402
        return (!async_err) ? posix_error() : NULL;
inline
                              
posix_error can be inlined into posix_fildes_fd with cost=10 (threshold=375) 
posix_fildes_fd
inline
                              
posix_error inlined into posix_fildes_fd 
posix_fildes_fd
1403
    Py_RETURN_NONE;
gvn
    
load of type i64 not eliminated because it is clobbered by call 
posix_fildes_fd
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_fchdir_impl
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_fchdir
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_fsync_impl
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_fsync
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_fdatasync_impl
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_fdatasync
1404
}
1405

1406

1407
#ifdef MS_WINDOWS
1408
/* This is a reimplementation of the C library's chdir function,
1409
   but one that produces Win32 errors instead of DOS error codes.
1410
   chdir is essentially a wrapper around SetCurrentDirectory; however,
1411
   it also needs to set "magic" environment variables indicating
1412
   the per-drive current directory, which are of the form =<drive>: */
1413
static BOOL __stdcall
1414
win32_wchdir(LPCWSTR path)
1415
{
1416
    wchar_t path_buf[MAX_PATH], *new_path = path_buf;
1417
    int result;
1418
    wchar_t env[4] = L"=x:";
1419

1420
    if(!SetCurrentDirectoryW(path))
1421
        return FALSE;
1422
    result = GetCurrentDirectoryW(Py_ARRAY_LENGTH(path_buf), new_path);
1423
    if (!result)
1424
        return FALSE;
1425
    if (result > Py_ARRAY_LENGTH(path_buf)) {
1426
        new_path = PyMem_RawMalloc(result * sizeof(wchar_t));
1427
        if (!new_path) {
1428
            SetLastError(ERROR_OUTOFMEMORY);
1429
            return FALSE;
1430
        }
1431
        result = GetCurrentDirectoryW(result, new_path);
1432
        if (!result) {
1433
            PyMem_RawFree(new_path);
1434
            return FALSE;
1435
        }
1436
    }
1437
    if (wcsncmp(new_path, L"\\\\", 2) == 0 ||
1438
        wcsncmp(new_path, L"//", 2) == 0)
1439
        /* UNC path, nothing to do. */
1440
        return TRUE;
1441
    env[1] = new_path[0];
1442
    result = SetEnvironmentVariableW(env, new_path);
1443
    if (new_path != path_buf)
1444
        PyMem_RawFree(new_path);
1445
    return result;
1446
}
1447
#endif
1448

1449
#ifdef MS_WINDOWS
1450
/* The CRT of Windows has a number of flaws wrt. its stat() implementation:
1451
   - time stamps are restricted to second resolution
1452
   - file modification times suffer from forth-and-back conversions between
1453
     UTC and local time
1454
   Therefore, we implement our own stat, based on the Win32 API directly.
1455
*/
1456
#define HAVE_STAT_NSEC 1
1457
#define HAVE_STRUCT_STAT_ST_FILE_ATTRIBUTES 1
1458

1459
static void
1460
find_data_to_file_info(WIN32_FIND_DATAW *pFileData,
1461
                       BY_HANDLE_FILE_INFORMATION *info,
1462
                       ULONG *reparse_tag)
1463
{
1464
    memset(info, 0, sizeof(*info));
1465
    info->dwFileAttributes = pFileData->dwFileAttributes;
1466
    info->ftCreationTime   = pFileData->ftCreationTime;
1467
    info->ftLastAccessTime = pFileData->ftLastAccessTime;
1468
    info->ftLastWriteTime  = pFileData->ftLastWriteTime;
1469
    info->nFileSizeHigh    = pFileData->nFileSizeHigh;
1470
    info->nFileSizeLow     = pFileData->nFileSizeLow;
1471
/*  info->nNumberOfLinks   = 1; */
1472
    if (pFileData->dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT)
1473
        *reparse_tag = pFileData->dwReserved0;
1474
    else
1475
        *reparse_tag = 0;
1476
}
1477

1478
static BOOL
1479
attributes_from_dir(LPCWSTR pszFile, BY_HANDLE_FILE_INFORMATION *info, ULONG *reparse_tag)
1480
{
1481
    HANDLE hFindFile;
1482
    WIN32_FIND_DATAW FileData;
1483
    hFindFile = FindFirstFileW(pszFile, &FileData);
1484
    if (hFindFile == INVALID_HANDLE_VALUE)
1485
        return FALSE;
1486
    FindClose(hFindFile);
1487
    find_data_to_file_info(&FileData, info, reparse_tag);
1488
    return TRUE;
1489
}
1490

1491
static BOOL
1492
get_target_path(HANDLE hdl, wchar_t **target_path)
1493
{
1494
    int buf_size, result_length;
1495
    wchar_t *buf;
1496

1497
    /* We have a good handle to the target, use it to determine
1498
       the target path name (then we'll call lstat on it). */
1499
    buf_size = GetFinalPathNameByHandleW(hdl, 0, 0,
1500
                                         VOLUME_NAME_DOS);
1501
    if(!buf_size)
1502
        return FALSE;
1503

1504
    buf = (wchar_t *)PyMem_RawMalloc((buf_size + 1) * sizeof(wchar_t));
1505
    if (!buf) {
1506
        SetLastError(ERROR_OUTOFMEMORY);
1507
        return FALSE;
1508
    }
1509

1510
    result_length = GetFinalPathNameByHandleW(hdl,
1511
                       buf, buf_size, VOLUME_NAME_DOS);
1512

1513
    if(!result_length) {
1514
        PyMem_RawFree(buf);
1515
        return FALSE;
1516
    }
1517

1518
    if(!CloseHandle(hdl)) {
1519
        PyMem_RawFree(buf);
1520
        return FALSE;
1521
    }
1522

1523
    buf[result_length] = 0;
1524

1525
    *target_path = buf;
1526
    return TRUE;
1527
}
1528

1529
static int
1530
win32_xstat_impl(const wchar_t *path, struct _Py_stat_struct *result,
1531
                 BOOL traverse)
1532
{
1533
    int code;
1534
    HANDLE hFile, hFile2;
1535
    BY_HANDLE_FILE_INFORMATION info;
1536
    ULONG reparse_tag = 0;
1537
    wchar_t *target_path;
1538
    const wchar_t *dot;
1539

1540
    hFile = CreateFileW(
1541
        path,
1542
        FILE_READ_ATTRIBUTES, /* desired access */
1543
        0, /* share mode */
1544
        NULL, /* security attributes */
1545
        OPEN_EXISTING,
1546
        /* FILE_FLAG_BACKUP_SEMANTICS is required to open a directory */
1547
        /* FILE_FLAG_OPEN_REPARSE_POINT does not follow the symlink.
1548
           Because of this, calls like GetFinalPathNameByHandle will return
1549
           the symlink path again and not the actual final path. */
1550
        FILE_ATTRIBUTE_NORMAL|FILE_FLAG_BACKUP_SEMANTICS|
1551
            FILE_FLAG_OPEN_REPARSE_POINT,
1552
        NULL);
1553

1554
    if (hFile == INVALID_HANDLE_VALUE) {
1555
        /* Either the target doesn't exist, or we don't have access to
1556
           get a handle to it. If the former, we need to return an error.
1557
           If the latter, we can use attributes_from_dir. */
1558
        DWORD lastError = GetLastError();
1559
        if (lastError != ERROR_ACCESS_DENIED &&
1560
            lastError != ERROR_SHARING_VIOLATION)
1561
            return -1;
1562
        /* Could not get attributes on open file. Fall back to
1563
           reading the directory. */
1564
        if (!attributes_from_dir(path, &info, &reparse_tag))
1565
            /* Very strange. This should not fail now */
1566
            return -1;
1567
        if (info.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) {
1568
            if (traverse) {
1569
                /* Should traverse, but could not open reparse point handle */
1570
                SetLastError(lastError);
1571
                return -1;
1572
            }
1573
        }
1574
    } else {
1575
        if (!GetFileInformationByHandle(hFile, &info)) {
1576
            CloseHandle(hFile);
1577
            return -1;
1578
        }
1579
        if (info.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) {
1580
            if (!win32_get_reparse_tag(hFile, &reparse_tag))
1581
                return -1;
1582

1583
            /* Close the outer open file handle now that we're about to
1584
               reopen it with different flags. */
1585
            if (!CloseHandle(hFile))
1586
                return -1;
1587

1588
            if (traverse) {
1589
                /* In order to call GetFinalPathNameByHandle we need to open
1590
                   the file without the reparse handling flag set. */
1591
                hFile2 = CreateFileW(
1592
                           path, FILE_READ_ATTRIBUTES, FILE_SHARE_READ,
1593
                           NULL, OPEN_EXISTING,
1594
                           FILE_ATTRIBUTE_NORMAL|FILE_FLAG_BACKUP_SEMANTICS,
1595
                           NULL);
1596
                if (hFile2 == INVALID_HANDLE_VALUE)
1597
                    return -1;
1598

1599
                if (!get_target_path(hFile2, &target_path))
1600
                    return -1;
1601

1602
                code = win32_xstat_impl(target_path, result, FALSE);
1603
                PyMem_RawFree(target_path);
1604
                return code;
1605
            }
1606
        } else
1607
            CloseHandle(hFile);
1608
    }
1609
    _Py_attribute_data_to_stat(&info, reparse_tag, result);
1610

1611
    /* Set S_IEXEC if it is an .exe, .bat, ... */
1612
    dot = wcsrchr(path, '.');
1613
    if (dot) {
1614
        if (_wcsicmp(dot, L".bat") == 0 || _wcsicmp(dot, L".cmd") == 0 ||
1615
            _wcsicmp(dot, L".exe") == 0 || _wcsicmp(dot, L".com") == 0)
1616
            result->st_mode |= 0111;
1617
    }
1618
    return 0;
1619
}
1620

1621
static int
1622
win32_xstat(const wchar_t *path, struct _Py_stat_struct *result, BOOL traverse)
1623
{
1624
    /* Protocol violation: we explicitly clear errno, instead of
1625
       setting it to a POSIX error. Callers should use GetLastError. */
1626
    int code = win32_xstat_impl(path, result, traverse);
1627
    errno = 0;
1628
    return code;
1629
}
1630
/* About the following functions: win32_lstat_w, win32_stat, win32_stat_w
1631

1632
   In Posix, stat automatically traverses symlinks and returns the stat
1633
   structure for the target.  In Windows, the equivalent GetFileAttributes by
1634
   default does not traverse symlinks and instead returns attributes for
1635
   the symlink.
1636

1637
   Therefore, win32_lstat will get the attributes traditionally, and
1638
   win32_stat will first explicitly resolve the symlink target and then will
1639
   call win32_lstat on that result. */
1640

1641
static int
1642
win32_lstat(const wchar_t* path, struct _Py_stat_struct *result)
1643
{
1644
    return win32_xstat(path, result, FALSE);
1645
}
1646

1647
static int
1648
win32_stat(const wchar_t* path, struct _Py_stat_struct *result)
1649
{
1650
    return win32_xstat(path, result, TRUE);
1651
}
1652

1653
#endif /* MS_WINDOWS */
1654

1655
PyDoc_STRVAR(stat_result__doc__,
1656
"stat_result: Result from stat, fstat, or lstat.\n\n\
1657
This object may be accessed either as a tuple of\n\
1658
  (mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime)\n\
1659
or via the attributes st_mode, st_ino, st_dev, st_nlink, st_uid, and so on.\n\
1660
\n\
1661
Posix/windows: If your platform supports st_blksize, st_blocks, st_rdev,\n\
1662
or st_flags, they are available as attributes only.\n\
1663
\n\
1664
See os.stat for more information.");
1665

1666
static PyStructSequence_Field stat_result_fields[] = {
1667
    {"st_mode",    "protection bits"},
1668
    {"st_ino",     "inode"},
1669
    {"st_dev",     "device"},
1670
    {"st_nlink",   "number of hard links"},
1671
    {"st_uid",     "user ID of owner"},
1672
    {"st_gid",     "group ID of owner"},
1673
    {"st_size",    "total size, in bytes"},
1674
    /* The NULL is replaced with PyStructSequence_UnnamedField later. */
1675
    {NULL,   "integer time of last access"},
1676
    {NULL,   "integer time of last modification"},
1677
    {NULL,   "integer time of last change"},
1678
    {"st_atime",   "time of last access"},
1679
    {"st_mtime",   "time of last modification"},
1680
    {"st_ctime",   "time of last change"},
1681
    {"st_atime_ns",   "time of last access in nanoseconds"},
1682
    {"st_mtime_ns",   "time of last modification in nanoseconds"},
1683
    {"st_ctime_ns",   "time of last change in nanoseconds"},
1684
#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
1685
    {"st_blksize", "blocksize for filesystem I/O"},
1686
#endif
1687
#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
1688
    {"st_blocks",  "number of blocks allocated"},
1689
#endif
1690
#ifdef HAVE_STRUCT_STAT_ST_RDEV
1691
    {"st_rdev",    "device type (if inode device)"},
1692
#endif
1693
#ifdef HAVE_STRUCT_STAT_ST_FLAGS
1694
    {"st_flags",   "user defined flags for file"},
1695
#endif
1696
#ifdef HAVE_STRUCT_STAT_ST_GEN
1697
    {"st_gen",    "generation number"},
1698
#endif
1699
#ifdef HAVE_STRUCT_STAT_ST_BIRTHTIME
1700
    {"st_birthtime",   "time of creation"},
1701
#endif
1702
#ifdef HAVE_STRUCT_STAT_ST_FILE_ATTRIBUTES
1703
    {"st_file_attributes", "Windows file attribute bits"},
1704
#endif
1705
    {0}
1706
};
1707

1708
#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
1709
#define ST_BLKSIZE_IDX 16
1710
#else
1711
#define ST_BLKSIZE_IDX 15
1712
#endif
1713

1714
#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
1715
#define ST_BLOCKS_IDX (ST_BLKSIZE_IDX+1)
1716
#else
1717
#define ST_BLOCKS_IDX ST_BLKSIZE_IDX
1718
#endif
1719

1720
#ifdef HAVE_STRUCT_STAT_ST_RDEV
1721
#define ST_RDEV_IDX (ST_BLOCKS_IDX+1)
1722
#else
1723
#define ST_RDEV_IDX ST_BLOCKS_IDX
1724
#endif
1725

1726
#ifdef HAVE_STRUCT_STAT_ST_FLAGS
1727
#define ST_FLAGS_IDX (ST_RDEV_IDX+1)
1728
#else
1729
#define ST_FLAGS_IDX ST_RDEV_IDX
1730
#endif
1731

1732
#ifdef HAVE_STRUCT_STAT_ST_GEN
1733
#define ST_GEN_IDX (ST_FLAGS_IDX+1)
1734
#else
1735
#define ST_GEN_IDX ST_FLAGS_IDX
1736
#endif
1737

1738
#ifdef HAVE_STRUCT_STAT_ST_BIRTHTIME
1739
#define ST_BIRTHTIME_IDX (ST_GEN_IDX+1)
1740
#else
1741
#define ST_BIRTHTIME_IDX ST_GEN_IDX
1742
#endif
1743

1744
#ifdef HAVE_STRUCT_STAT_ST_FILE_ATTRIBUTES
1745
#define ST_FILE_ATTRIBUTES_IDX (ST_BIRTHTIME_IDX+1)
1746
#else
1747
#define ST_FILE_ATTRIBUTES_IDX ST_BIRTHTIME_IDX
1748
#endif
1749

1750
static PyStructSequence_Desc stat_result_desc = {
1751
    "stat_result", /* name */
1752
    stat_result__doc__, /* doc */
1753
    stat_result_fields,
1754
    10
1755
};
1756

1757
PyDoc_STRVAR(statvfs_result__doc__,
1758
"statvfs_result: Result from statvfs or fstatvfs.\n\n\
1759
This object may be accessed either as a tuple of\n\
1760
  (bsize, frsize, blocks, bfree, bavail, files, ffree, favail, flag, namemax),\n\
1761
or via the attributes f_bsize, f_frsize, f_blocks, f_bfree, and so on.\n\
1762
\n\
1763
See os.statvfs for more information.");
1764

1765
static PyStructSequence_Field statvfs_result_fields[] = {
1766
    {"f_bsize",  },
1767
    {"f_frsize", },
1768
    {"f_blocks", },
1769
    {"f_bfree",  },
1770
    {"f_bavail", },
1771
    {"f_files",  },
1772
    {"f_ffree",  },
1773
    {"f_favail", },
1774
    {"f_flag",   },
1775
    {"f_namemax",},
1776
    {0}
1777
};
1778

1779
static PyStructSequence_Desc statvfs_result_desc = {
1780
    "statvfs_result", /* name */
1781
    statvfs_result__doc__, /* doc */
1782
    statvfs_result_fields,
1783
    10
1784
};
1785

1786
#if defined(HAVE_WAITID) && !defined(__APPLE__)
1787
PyDoc_STRVAR(waitid_result__doc__,
1788
"waitid_result: Result from waitid.\n\n\
1789
This object may be accessed either as a tuple of\n\
1790
  (si_pid, si_uid, si_signo, si_status, si_code),\n\
1791
or via the attributes si_pid, si_uid, and so on.\n\
1792
\n\
1793
See os.waitid for more information.");
1794

1795
static PyStructSequence_Field waitid_result_fields[] = {
1796
    {"si_pid",  },
1797
    {"si_uid", },
1798
    {"si_signo", },
1799
    {"si_status",  },
1800
    {"si_code", },
1801
    {0}
1802
};
1803

1804
static PyStructSequence_Desc waitid_result_desc = {
1805
    "waitid_result", /* name */
1806
    waitid_result__doc__, /* doc */
1807
    waitid_result_fields,
1808
    5
1809
};
1810
static PyTypeObject WaitidResultType;
1811
#endif
1812

1813
static int initialized;
1814
static PyTypeObject StatResultType;
1815
static PyTypeObject StatVFSResultType;
1816
#if defined(HAVE_SCHED_SETPARAM) || defined(HAVE_SCHED_SETSCHEDULER)
1817
static PyTypeObject SchedParamType;
1818
#endif
1819
static newfunc structseq_new;
1820

1821
static PyObject *
1822
statresult_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
1823
{
1824
    PyStructSequence *result;
1825
    int i;
1826

1827
    result = (PyStructSequence*)structseq_new(type, args, kwds);
1828
    if (!result)
1829
        return NULL;
1830
    /* If we have been initialized from a tuple,
1831
       st_?time might be set to None. Initialize it
1832
       from the int slots.  */
1833
    for (i = 7; i <= 9; i++) {
loop-unroll
    
completely unrolled loop with 3 iterations 
statresult_new
1834
        if (result->ob_item[i+3] == Py_None) {
licm
                    
hosting getelementptr 
statresult_new
gvn
            
load of type %struct._object* not eliminated because it is clobbered by call 
statresult_new
1835
            Py_DECREF(Py_None);
licm
            
failed to move load with loop-invariant address because the loop may invalidate its value 
statresult_new
gvn
            
load of type i64 not eliminated because it is clobbered by call 
statresult_new
1836
            Py_INCREF(result->ob_item[i]);
gvn
            
load of type %struct._object* not eliminated because it is clobbered by call 
statresult_new
1837
            result->ob_item[i+3] = result->ob_item[i];
1838
        }
1839
    }
1840
    return (PyObject*)result;
1841
}
1842

1843

1844

1845
/* If true, st_?time is float. */
1846
static int _stat_float_times = 1;
1847

1848
PyDoc_STRVAR(stat_float_times__doc__,
1849
"stat_float_times([newval]) -> oldval\n\n\
1850
Determine whether os.[lf]stat represents time stamps as float objects.\n\
1851
\n\
1852
If value is True, future calls to stat() return floats; if it is False,\n\
1853
future calls return ints.\n\
1854
If value is omitted, return the current setting.\n");
1855

1856
/* AC 3.5: the public default value should be None, not ready for that yet */
1857
static PyObject*
1858
stat_float_times(PyObject* self, PyObject *args)
1859
{
1860
    int newval = -1;
1861
    if (!PyArg_ParseTuple(args, "|i:stat_float_times", &newval))
inline
         
_PyArg_ParseTuple_SizeT will not be inlined into stat_float_times because its definition is unavailable 
stat_float_times
1862
        return NULL;
1863
    if (PyErr_WarnEx(PyExc_DeprecationWarning,
inline
        
PyErr_WarnEx will not be inlined into stat_float_times because its definition is unavailable 
stat_float_times
gvn
                     
load of type %struct._object* not eliminated because it is clobbered by call 
stat_float_times
1864
                     "stat_float_times() is deprecated",
1865
                     1))
1866
        return NULL;
1867
    if (newval == -1)
gvn
        
load of type i32 not eliminated in favor of store because it is clobbered by call 
stat_float_times
1868
        /* Return old value */
1869
        return PyBool_FromLong(_stat_float_times);
inline
               
PyBool_FromLong will not be inlined into stat_float_times because its definition is unavailable 
stat_float_times
gvn
                               
load of type i32 not eliminated because it is clobbered by call 
stat_float_times
1870
    _stat_float_times = newval;
1871
    Py_INCREF(Py_None);
gvn
    
load of type i64 not eliminated because it is clobbered by call 
stat_float_times
1872
    return Py_None;
1873
}
1874

1875
static PyObject *billion = NULL;
1876

1877
static void
1878
fill_time(PyObject *v, int index, time_t sec, unsigned long nsec)
1879
{
1880
    PyObject *s = _PyLong_FromTime_t(sec);
inline
                  
_PyLong_FromTime_t will not be inlined into fill_time because its definition is unavailable 
fill_time
1881
    PyObject *ns_fractional = PyLong_FromUnsignedLong(nsec);
inline
                              
PyLong_FromUnsignedLong will not be inlined into fill_time because its definition is unavailable 
fill_time
1882
    PyObject *s_in_ns = NULL;
1883
    PyObject *ns_total = NULL;
1884
    PyObject *float_s = NULL;
1885

1886
    if (!(s && ns_fractional))
1887
        goto exit;
1888

1889
    s_in_ns = PyNumber_Multiply(s, billion);
inline
              
PyNumber_Multiply will not be inlined into fill_time because its definition is unavailable 
fill_time
gvn
                                   
load of type %struct._object* not eliminated because it is clobbered by call 
fill_time
1890
    if (!s_in_ns)
1891
        goto exit;
1892

1893
    ns_total = PyNumber_Add(s_in_ns, ns_fractional);
inline
               
PyNumber_Add will not be inlined into fill_time because its definition is unavailable 
fill_time
1894
    if (!ns_total)
1895
        goto exit;
1896

1897
    if (_stat_float_times) {
gvn
        
load of type i32 not eliminated because it is clobbered by call 
fill_time
1898
        float_s = PyFloat_FromDouble(sec + 1e-9*nsec);
inline
                  
PyFloat_FromDouble will not be inlined into fill_time because its definition is unavailable 
fill_time
1899
        if (!float_s)
1900
            goto exit;
1901
    }
1902
    else {
1903
        float_s = s;
1904
        Py_INCREF(float_s);
gvn
        
load of type i64 not eliminated because it is clobbered by call 
fill_time
1905
    }
1906

1907
    PyStructSequence_SET_ITEM(v, index, s);
1908
    PyStructSequence_SET_ITEM(v, index+3, float_s);
1909
    PyStructSequence_SET_ITEM(v, index+6, ns_total);
1910
    s = NULL;
1911
    float_s = NULL;
1912
    ns_total = NULL;
1913
exit:
1914
    Py_XDECREF(s);
gvn
    
load of type i64 not eliminated because it is clobbered by call 
fill_time
1915
    Py_XDECREF(ns_fractional);
gvn
    
load of type i64 not eliminated because it is clobbered by call 
fill_time
1916
    Py_XDECREF(s_in_ns);
gvn
    
load of type i64 not eliminated because it is clobbered by call 
fill_time
1917
    Py_XDECREF(ns_total);
gvn
    
load of type i64 not eliminated because it is clobbered by call 
fill_time
1918
    Py_XDECREF(float_s);
1919
}
1920

1921
/* pack a system stat C structure into the Python stat tuple
1922
   (used by posix_stat() and posix_fstat()) */
1923
static PyObject*
1924
_pystat_fromstructstat(STRUCT_STAT *st)
1925
{
1926
    unsigned long ansec, mnsec, cnsec;
1927
    PyObject *v = PyStructSequence_New(&StatResultType);
inline
                  
PyStructSequence_New will not be inlined into _pystat_fromstructstat because its definition is unavailable 
_pystat_fromstructstat
1928
    if (v == NULL)
1929
        return NULL;
1930

1931
    PyStructSequence_SET_ITEM(v, 0, PyLong_FromLong((long)st->st_mode));
inline
    
PyLong_FromLong will not be inlined into _pystat_fromstructstat because its definition is unavailable 
_pystat_fromstructstat
gvn
    
load of type i32 not eliminated because it is clobbered by call 
_pystat_fromstructstat
1932
#ifdef HAVE_LARGEFILE_SUPPORT
1933
    PyStructSequence_SET_ITEM(v, 1,
1934
                              PyLong_FromLongLong((long long)st->st_ino));
1935
#else
1936
    PyStructSequence_SET_ITEM(v, 1, PyLong_FromLong((long)st->st_ino));
inline
    
PyLong_FromLong will not be inlined into _pystat_fromstructstat because its definition is unavailable 
_pystat_fromstructstat
gvn
    
load of type i64 not eliminated because it is clobbered by call 
_pystat_fromstructstat
1937
#endif
1938
#ifdef MS_WINDOWS
1939
    PyStructSequence_SET_ITEM(v, 2, PyLong_FromUnsignedLong(st->st_dev));
1940
#else
1941
    PyStructSequence_SET_ITEM(v, 2, _PyLong_FromDev(st->st_dev));
inline
    
PyLong_FromLongLong will not be inlined into _pystat_fromstructstat because its definition is unavailable 
_pystat_fromstructstat
gvn
    
load of type i64 not eliminated because it is clobbered by call 
_pystat_fromstructstat
1942
#endif
1943
    PyStructSequence_SET_ITEM(v, 3, PyLong_FromLong((long)st->st_nlink));
inline
    
PyLong_FromLong will not be inlined into _pystat_fromstructstat because its definition is unavailable 
_pystat_fromstructstat
gvn
    
load of type i64 not eliminated because it is clobbered by call 
_pystat_fromstructstat
1944
#if defined(MS_WINDOWS)
1945
    PyStructSequence_SET_ITEM(v, 4, PyLong_FromLong(0));
1946
    PyStructSequence_SET_ITEM(v, 5, PyLong_FromLong(0));
1947
#else
1948
    PyStructSequence_SET_ITEM(v, 4, _PyLong_FromUid(st->st_uid));
inline
    
_PyLong_FromUid can be inlined into _pystat_fromstructstat with cost=45 (threshold=250) 
_pystat_fromstructstat
inline
    
_PyLong_FromUid inlined into _pystat_fromstructstat 
_pystat_fromstructstat
gvn
    
load of type i32 not eliminated because it is clobbered by call 
_pystat_fromstructstat
1949
    PyStructSequence_SET_ITEM(v, 5, _PyLong_FromGid(st->st_gid));
inline
    
_PyLong_FromGid can be inlined into _pystat_fromstructstat with cost=45 (threshold=250) 
_pystat_fromstructstat
inline
    
_PyLong_FromGid inlined into _pystat_fromstructstat 
_pystat_fromstructstat
gvn
    
load of type i32 not eliminated because it is clobbered by call 
_pystat_fromstructstat
1950
#endif
1951
#ifdef HAVE_LARGEFILE_SUPPORT
1952
    PyStructSequence_SET_ITEM(v, 6,
1953
                              PyLong_FromLongLong((long long)st->st_size));
1954
#else
1955
    PyStructSequence_SET_ITEM(v, 6, PyLong_FromLong(st->st_size));
inline
    
PyLong_FromLong will not be inlined into _pystat_fromstructstat because its definition is unavailable 
_pystat_fromstructstat
gvn
    
load of type i64 not eliminated because it is clobbered by call 
_pystat_fromstructstat
1956
#endif
1957

1958
#if defined(HAVE_STAT_TV_NSEC)
1959
    ansec = st->st_atim.tv_nsec;
gvn
                        
load of type i64 not eliminated because it is clobbered by call 
_pystat_fromstructstat
1960
    mnsec = st->st_mtim.tv_nsec;
gvn
                        
load of type i64 not eliminated because it is clobbered by call 
_pystat_fromstructstat
1961
    cnsec = st->st_ctim.tv_nsec;
gvn
                        
load of type i64 not eliminated because it is clobbered by call 
_pystat_fromstructstat
1962
#elif defined(HAVE_STAT_TV_NSEC2)
1963
    ansec = st->st_atimespec.tv_nsec;
1964
    mnsec = st->st_mtimespec.tv_nsec;
1965
    cnsec = st->st_ctimespec.tv_nsec;
1966
#elif defined(HAVE_STAT_NSEC)
1967
    ansec = st->st_atime_nsec;
1968
    mnsec = st->st_mtime_nsec;
1969
    cnsec = st->st_ctime_nsec;
1970
#else
1971
    ansec = mnsec = cnsec = 0;
1972
#endif
1973
    fill_time(v, 7, st->st_atime, ansec);
inline
    
fill_time too costly to inline (cost=470, threshold=250) 
_pystat_fromstructstat
inline
    
fill_time will not be inlined into _pystat_fromstructstat 
_pystat_fromstructstat
gvn
                        
load of type i64 not eliminated because it is clobbered by call 
_pystat_fromstructstat
1974
    fill_time(v, 8, st->st_mtime, mnsec);
inline
    
fill_time too costly to inline (cost=470, threshold=250) 
_pystat_fromstructstat
inline
    
fill_time will not be inlined into _pystat_fromstructstat 
_pystat_fromstructstat
gvn
                        
load of type i64 not eliminated because it is clobbered by call 
_pystat_fromstructstat
1975
    fill_time(v, 9, st->st_ctime, cnsec);
inline
    
fill_time too costly to inline (cost=470, threshold=250) 
_pystat_fromstructstat
inline
    
fill_time will not be inlined into _pystat_fromstructstat 
_pystat_fromstructstat
gvn
                        
load of type i64 not eliminated because it is clobbered by call 
_pystat_fromstructstat
1976

1977
#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
1978
    PyStructSequence_SET_ITEM(v, ST_BLKSIZE_IDX,
inline
    
PyLong_FromLong will not be inlined into _pystat_fromstructstat because its definition is unavailable 
_pystat_fromstructstat
gvn
    
load of type i64 not eliminated because it is clobbered by call 
_pystat_fromstructstat
1979
                              PyLong_FromLong((long)st->st_blksize));
1980
#endif
1981
#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
1982
    PyStructSequence_SET_ITEM(v, ST_BLOCKS_IDX,
inline
    
PyLong_FromLong will not be inlined into _pystat_fromstructstat because its definition is unavailable 
_pystat_fromstructstat
gvn
    
load of type i64 not eliminated because it is clobbered by call 
_pystat_fromstructstat
1983
                              PyLong_FromLong((long)st->st_blocks));
1984
#endif
1985
#ifdef HAVE_STRUCT_STAT_ST_RDEV
1986
    PyStructSequence_SET_ITEM(v, ST_RDEV_IDX,
inline
    
PyLong_FromLong will not be inlined into _pystat_fromstructstat because its definition is unavailable 
_pystat_fromstructstat
gvn
    
load of type i64 not eliminated because it is clobbered by call 
_pystat_fromstructstat
1987
                              PyLong_FromLong((long)st->st_rdev));
1988
#endif
1989
#ifdef HAVE_STRUCT_STAT_ST_GEN
1990
    PyStructSequence_SET_ITEM(v, ST_GEN_IDX,
1991
                              PyLong_FromLong((long)st->st_gen));
1992
#endif
1993
#ifdef HAVE_STRUCT_STAT_ST_BIRTHTIME
1994
    {
1995
      PyObject *val;
1996
      unsigned long bsec,bnsec;
1997
      bsec = (long)st->st_birthtime;
1998
#ifdef HAVE_STAT_TV_NSEC2
1999
      bnsec = st->st_birthtimespec.tv_nsec;
2000
#else
2001
      bnsec = 0;
2002
#endif
2003
      if (_stat_float_times) {
2004
        val = PyFloat_FromDouble(bsec + 1e-9*bnsec);
2005
      } else {
2006
        val = PyLong_FromLong((long)bsec);
2007
      }
2008
      PyStructSequence_SET_ITEM(v, ST_BIRTHTIME_IDX,
2009
                                val);
2010
    }
2011
#endif
2012
#ifdef HAVE_STRUCT_STAT_ST_FLAGS
2013
    PyStructSequence_SET_ITEM(v, ST_FLAGS_IDX,
2014
                              PyLong_FromLong((long)st->st_flags));
2015
#endif
2016
#ifdef HAVE_STRUCT_STAT_ST_FILE_ATTRIBUTES
2017
    PyStructSequence_SET_ITEM(v, ST_FILE_ATTRIBUTES_IDX,
2018
                              PyLong_FromUnsignedLong(st->st_file_attributes));
2019
#endif
2020

2021
    if (PyErr_Occurred()) {
inline
        
PyErr_Occurred will not be inlined into _pystat_fromstructstat because its definition is unavailable 
_pystat_fromstructstat
2022
        Py_DECREF(v);
gvn
        
load of type i64 not eliminated because it is clobbered by call 
_pystat_fromstructstat
2023
        return NULL;
2024
    }
2025

2026
    return v;
2027
}
2028

2029
/* POSIX methods */
2030

2031

2032
static PyObject *
2033
posix_do_stat(const char *function_name, path_t *path,
2034
              int dir_fd, int follow_symlinks)
2035
{
2036
    STRUCT_STAT st;
2037
    int result;
2038

2039
#if !defined(MS_WINDOWS) && !defined(HAVE_FSTATAT) && !defined(HAVE_LSTAT)
2040
    if (follow_symlinks_specified(function_name, follow_symlinks))
2041
        return NULL;
2042
#endif
2043

2044
    if (path_and_dir_fd_invalid("stat", path, dir_fd) ||
inline
        
path_and_dir_fd_invalid can be inlined into posix_do_stat with cost=45 (threshold=250) 
posix_do_stat
inline
        
path_and_dir_fd_invalid inlined into posix_do_stat 
posix_do_stat
2045
        dir_fd_and_fd_invalid("stat", dir_fd, path->fd) ||
inline
        
dir_fd_and_fd_invalid can be inlined into posix_do_stat with cost=25 (threshold=250) 
posix_do_stat
inline
        
dir_fd_and_fd_invalid inlined into posix_do_stat 
posix_do_stat
2046
        fd_and_follow_symlinks_invalid("stat", path->fd, follow_symlinks))
inline
        
fd_and_follow_symlinks_invalid can be inlined into posix_do_stat with cost=25 (threshold=250) 
posix_do_stat
inline
        
fd_and_follow_symlinks_invalid inlined into posix_do_stat 
posix_do_stat
gvn
                                                     
load of type i32 eliminated in favor of load 
posix_do_stat
2047
        return NULL;
2048

2049
    Py_BEGIN_ALLOW_THREADS
inline
    
PyEval_SaveThread will not be inlined into posix_do_stat because its definition is unavailable 
posix_do_stat
2050
    if (path->fd != -1)
gvn
              
load of type i32 not eliminated in favor of load because it is clobbered by call 
posix_do_stat
2051
        result = FSTAT(path->fd, &st);
inline
                 
fstat64 can be inlined into posix_do_stat with cost=5 (threshold=487) 
posix_do_stat
inline
                 
fstat64 inlined into posix_do_stat 
posix_do_stat
2052
#ifdef MS_WINDOWS
2053
    else if (follow_symlinks)
2054
        result = win32_stat(path->wide, &st);
2055
    else
2056
        result = win32_lstat(path->wide, &st);
2057
#else
2058
    else
2059
#if defined(HAVE_LSTAT)
2060
    if ((!follow_symlinks) && (dir_fd == DEFAULT_DIR_FD))
2061
        result = LSTAT(path->narrow, &st);
inline
                 
lstat64 can be inlined into posix_do_stat with cost=5 (threshold=487) 
posix_do_stat
inline
                 
lstat64 inlined into posix_do_stat 
posix_do_stat
gvn
                             
load of type i8* not eliminated because it is clobbered by call 
posix_do_stat
2062
    else
2063
#endif /* HAVE_LSTAT */
2064
#ifdef HAVE_FSTATAT
2065
    if ((dir_fd != DEFAULT_DIR_FD) || !follow_symlinks)
2066
        result = fstatat(dir_fd, path->narrow, &st,
inline
                 
fstatat64 can be inlined into posix_do_stat with cost=5 (threshold=487) 
posix_do_stat
inline
                 
fstatat64 inlined into posix_do_stat 
posix_do_stat
2067
                         follow_symlinks ? 0 : AT_SYMLINK_NOFOLLOW);
2068
    else
2069
#endif /* HAVE_FSTATAT */
2070
        result = STAT(path->narrow, &st);
inline
                 
stat64 can be inlined into posix_do_stat with cost=5 (threshold=487) 
posix_do_stat
inline
                 
stat64 inlined into posix_do_stat 
posix_do_stat
2071
#endif /* MS_WINDOWS */
2072
    Py_END_ALLOW_THREADS
inline
    
PyEval_RestoreThread will not be inlined into posix_do_stat because its definition is unavailable 
posix_do_stat
2073

2074
    if (result != 0) {
2075
        return path_error(path);
inline
               
path_error can be inlined into posix_do_stat with cost=10 (threshold=375) 
posix_do_stat
inline
               
path_error inlined into posix_do_stat 
posix_do_stat
2076
    }
2077

2078
    return _pystat_fromstructstat(&st);
inline
           
_pystat_fromstructstat too costly to inline (cost=645, threshold=625) 
posix_do_stat
inline
           
_pystat_fromstructstat will not be inlined into posix_do_stat 
posix_do_stat
2079
}
2080

2081
/*[python input]
2082

2083
for s in """
2084

2085
FACCESSAT
2086
FCHMODAT
2087
FCHOWNAT
2088
FSTATAT
2089
LINKAT
2090
MKDIRAT
2091
MKFIFOAT
2092
MKNODAT
2093
OPENAT
2094
READLINKAT
2095
SYMLINKAT
2096
UNLINKAT
2097

2098
""".strip().split():
2099
    s = s.strip()
2100
    print("""
2101
#ifdef HAVE_{s}
2102
    #define {s}_DIR_FD_CONVERTER dir_fd_converter
2103
#else
2104
    #define {s}_DIR_FD_CONVERTER dir_fd_unavailable
2105
#endif
2106
""".rstrip().format(s=s))
2107

2108
for s in """
2109

2110
FCHDIR
2111
FCHMOD
2112
FCHOWN
2113
FDOPENDIR
2114
FEXECVE
2115
FPATHCONF
2116
FSTATVFS
2117
FTRUNCATE
2118

2119
""".strip().split():
2120
    s = s.strip()
2121
    print("""
2122
#ifdef HAVE_{s}
2123
    #define PATH_HAVE_{s} 1
2124
#else
2125
    #define PATH_HAVE_{s} 0
2126
#endif
2127

2128
""".rstrip().format(s=s))
2129
[python start generated code]*/
2130

2131
#ifdef HAVE_FACCESSAT
2132
    #define FACCESSAT_DIR_FD_CONVERTER dir_fd_converter
2133
#else
2134
    #define FACCESSAT_DIR_FD_CONVERTER dir_fd_unavailable
2135
#endif
2136

2137
#ifdef HAVE_FCHMODAT
2138
    #define FCHMODAT_DIR_FD_CONVERTER dir_fd_converter
2139
#else
2140
    #define FCHMODAT_DIR_FD_CONVERTER dir_fd_unavailable
2141
#endif
2142

2143
#ifdef HAVE_FCHOWNAT
2144
    #define FCHOWNAT_DIR_FD_CONVERTER dir_fd_converter
2145
#else
2146
    #define FCHOWNAT_DIR_FD_CONVERTER dir_fd_unavailable
2147
#endif
2148

2149
#ifdef HAVE_FSTATAT
2150
    #define FSTATAT_DIR_FD_CONVERTER dir_fd_converter
2151
#else
2152
    #define FSTATAT_DIR_FD_CONVERTER dir_fd_unavailable
2153
#endif
2154

2155
#ifdef HAVE_LINKAT
2156
    #define LINKAT_DIR_FD_CONVERTER dir_fd_converter
2157
#else
2158
    #define LINKAT_DIR_FD_CONVERTER dir_fd_unavailable
2159
#endif
2160

2161
#ifdef HAVE_MKDIRAT
2162
    #define MKDIRAT_DIR_FD_CONVERTER dir_fd_converter
2163
#else
2164
    #define MKDIRAT_DIR_FD_CONVERTER dir_fd_unavailable
2165
#endif
2166

2167
#ifdef HAVE_MKFIFOAT
2168
    #define MKFIFOAT_DIR_FD_CONVERTER dir_fd_converter
2169
#else
2170
    #define MKFIFOAT_DIR_FD_CONVERTER dir_fd_unavailable
2171
#endif
2172

2173
#ifdef HAVE_MKNODAT
2174
    #define MKNODAT_DIR_FD_CONVERTER dir_fd_converter
2175
#else
2176
    #define MKNODAT_DIR_FD_CONVERTER dir_fd_unavailable
2177
#endif
2178

2179
#ifdef HAVE_OPENAT
2180
    #define OPENAT_DIR_FD_CONVERTER dir_fd_converter
2181
#else
2182
    #define OPENAT_DIR_FD_CONVERTER dir_fd_unavailable
2183
#endif
2184

2185
#ifdef HAVE_READLINKAT
2186
    #define READLINKAT_DIR_FD_CONVERTER dir_fd_converter
2187
#else
2188
    #define READLINKAT_DIR_FD_CONVERTER dir_fd_unavailable
2189
#endif
2190

2191
#ifdef HAVE_SYMLINKAT
2192
    #define SYMLINKAT_DIR_FD_CONVERTER dir_fd_converter
2193
#else
2194
    #define SYMLINKAT_DIR_FD_CONVERTER dir_fd_unavailable
2195
#endif
2196

2197
#ifdef HAVE_UNLINKAT
2198
    #define UNLINKAT_DIR_FD_CONVERTER dir_fd_converter
2199
#else
2200
    #define UNLINKAT_DIR_FD_CONVERTER dir_fd_unavailable
2201
#endif
2202

2203
#ifdef HAVE_FCHDIR
2204
    #define PATH_HAVE_FCHDIR 1
2205
#else
2206
    #define PATH_HAVE_FCHDIR 0
2207
#endif
2208

2209
#ifdef HAVE_FCHMOD
2210
    #define PATH_HAVE_FCHMOD 1
2211
#else
2212
    #define PATH_HAVE_FCHMOD 0
2213
#endif
2214

2215
#ifdef HAVE_FCHOWN
2216
    #define PATH_HAVE_FCHOWN 1
2217
#else
2218
    #define PATH_HAVE_FCHOWN 0
2219
#endif
2220

2221
#ifdef HAVE_FDOPENDIR
2222
    #define PATH_HAVE_FDOPENDIR 1
2223
#else
2224
    #define PATH_HAVE_FDOPENDIR 0
2225
#endif
2226

2227
#ifdef HAVE_FEXECVE
2228
    #define PATH_HAVE_FEXECVE 1
2229
#else
2230
    #define PATH_HAVE_FEXECVE 0
2231
#endif
2232

2233
#ifdef HAVE_FPATHCONF
2234
    #define PATH_HAVE_FPATHCONF 1
2235
#else
2236
    #define PATH_HAVE_FPATHCONF 0
2237
#endif
2238

2239
#ifdef HAVE_FSTATVFS
2240
    #define PATH_HAVE_FSTATVFS 1
2241
#else
2242
    #define PATH_HAVE_FSTATVFS 0
2243
#endif
2244

2245
#ifdef HAVE_FTRUNCATE
2246
    #define PATH_HAVE_FTRUNCATE 1
2247
#else
2248
    #define PATH_HAVE_FTRUNCATE 0
2249
#endif
2250
/*[python end generated code: output=4bd4f6f7d41267f1 input=80b4c890b6774ea5]*/
2251

2252
#ifdef MS_WINDOWS
2253
    #undef PATH_HAVE_FTRUNCATE
2254
    #define PATH_HAVE_FTRUNCATE 1
2255
#endif
2256

2257
/*[python input]
2258

2259
class path_t_converter(CConverter):
2260

2261
    type = "path_t"
2262
    impl_by_reference = True
2263
    parse_by_reference = True
2264

2265
    converter = 'path_converter'
2266

2267
    def converter_init(self, *, allow_fd=False, nullable=False):
2268
        # right now path_t doesn't support default values.
2269
        # to support a default value, you'll need to override initialize().
2270
        if self.default not in (unspecified, None):
2271
            fail("Can't specify a default to the path_t converter!")
2272

2273
        if self.c_default not in (None, 'Py_None'):
2274
            raise RuntimeError("Can't specify a c_default to the path_t converter!")
2275

2276
        self.nullable = nullable
2277
        self.allow_fd = allow_fd
2278

2279
    def pre_render(self):
2280
        def strify(value):
2281
            if isinstance(value, str):
2282
                return value
2283
            return str(int(bool(value)))
2284

2285
        # add self.py_name here when merging with posixmodule conversion
2286
        self.c_default = 'PATH_T_INITIALIZE("{}", "{}", {}, {})'.format(
2287
            self.function.name,
2288
            self.name,
2289
            strify(self.nullable),
2290
            strify(self.allow_fd),
2291
            )
2292

2293
    def cleanup(self):
2294
        return "path_cleanup(&" + self.name + ");\n"
2295

2296

2297
class dir_fd_converter(CConverter):
2298
    type = 'int'
2299

2300
    def converter_init(self, requires=None):
2301
        if self.default in (unspecified, None):
2302
            self.c_default = 'DEFAULT_DIR_FD'
2303
        if isinstance(requires, str):
2304
            self.converter = requires.upper() + '_DIR_FD_CONVERTER'
2305
        else:
2306
            self.converter = 'dir_fd_converter'
2307

2308
class fildes_converter(CConverter):
2309
    type = 'int'
2310
    converter = 'fildes_converter'
2311

2312
class uid_t_converter(CConverter):
2313
    type = "uid_t"
2314
    converter = '_Py_Uid_Converter'
2315

2316
class gid_t_converter(CConverter):
2317
    type = "gid_t"
2318
    converter = '_Py_Gid_Converter'
2319

2320
class dev_t_converter(CConverter):
2321
    type = 'dev_t'
2322
    converter = '_Py_Dev_Converter'
2323

2324
class dev_t_return_converter(unsigned_long_return_converter):
2325
    type = 'dev_t'
2326
    conversion_fn = '_PyLong_FromDev'
2327
    unsigned_cast = '(dev_t)'
2328

2329
class FSConverter_converter(CConverter):
2330
    type = 'PyObject *'
2331
    converter = 'PyUnicode_FSConverter'
2332
    def converter_init(self):
2333
        if self.default is not unspecified:
2334
            fail("FSConverter_converter does not support default values")
2335
        self.c_default = 'NULL'
2336

2337
    def cleanup(self):
2338
        return "Py_XDECREF(" + self.name + ");\n"
2339

2340
class pid_t_converter(CConverter):
2341
    type = 'pid_t'
2342
    format_unit = '" _Py_PARSE_PID "'
2343

2344
class idtype_t_converter(int_converter):
2345
    type = 'idtype_t'
2346

2347
class id_t_converter(CConverter):
2348
    type = 'id_t'
2349
    format_unit = '" _Py_PARSE_PID "'
2350

2351
class intptr_t_converter(CConverter):
2352
    type = 'intptr_t'
2353
    format_unit = '" _Py_PARSE_INTPTR "'
2354

2355
class Py_off_t_converter(CConverter):
2356
    type = 'Py_off_t'
2357
    converter = 'Py_off_t_converter'
2358

2359
class Py_off_t_return_converter(long_return_converter):
2360
    type = 'Py_off_t'
2361
    conversion_fn = 'PyLong_FromPy_off_t'
2362

2363
class path_confname_converter(CConverter):
2364
    type="int"
2365
    converter="conv_path_confname"
2366

2367
class confstr_confname_converter(path_confname_converter):
2368
    converter='conv_confstr_confname'
2369

2370
class sysconf_confname_converter(path_confname_converter):
2371
    converter="conv_sysconf_confname"
2372

2373
class sched_param_converter(CConverter):
2374
    type = 'struct sched_param'
2375
    converter = 'convert_sched_param'
2376
    impl_by_reference = True;
2377

2378
[python start generated code]*/
2379
/*[python end generated code: output=da39a3ee5e6b4b0d input=418fce0e01144461]*/
2380

2381
/*[clinic input]
2382

2383
os.stat
2384

2385
    path : path_t(allow_fd=True)
2386
        Path to be examined; can be string, bytes, or open-file-descriptor int.
2387

2388
    *
2389

2390
    dir_fd : dir_fd(requires='fstatat') = None
2391
        If not None, it should be a file descriptor open to a directory,
2392
        and path should be a relative string; path will then be relative to
2393
        that directory.
2394

2395
    follow_symlinks: bool = True
2396
        If False, and the last element of the path is a symbolic link,
2397
        stat will examine the symbolic link itself instead of the file
2398
        the link points to.
2399

2400
Perform a stat system call on the given path.
2401

2402
dir_fd and follow_symlinks may not be implemented
2403
  on your platform.  If they are unavailable, using them will raise a
2404
  NotImplementedError.
2405

2406
It's an error to use dir_fd or follow_symlinks when specifying path as
2407
  an open file descriptor.
2408

2409
[clinic start generated code]*/
2410

2411
static PyObject *
2412
os_stat_impl(PyObject *module, path_t *path, int dir_fd, int follow_symlinks)
2413
/*[clinic end generated code: output=7d4976e6f18a59c5 input=099d356c306fa24a]*/
2414
{
2415
    return posix_do_stat("stat", path, dir_fd, follow_symlinks);
inline
           
posix_do_stat too costly to inline (cost=595, threshold=250) 
os_stat_impl
inline
           
posix_do_stat will not be inlined into os_stat_impl 
os_stat_impl
inline
           
posix_do_stat too costly to inline (cost=565, threshold=250) 
os_stat
inline
           
posix_do_stat will not be inlined into os_stat 
os_stat
2416
}
2417

2418

2419
/*[clinic input]
2420
os.lstat
2421

2422
    path : path_t
2423

2424
    *
2425

2426
    dir_fd : dir_fd(requires='fstatat') = None
2427

2428
Perform a stat system call on the given path, without following symbolic links.
2429

2430
Like stat(), but do not follow symbolic links.
2431
Equivalent to stat(path, follow_symlinks=False).
2432
[clinic start generated code]*/
2433

2434
static PyObject *
2435
os_lstat_impl(PyObject *module, path_t *path, int dir_fd)
2436
/*[clinic end generated code: output=ef82a5d35ce8ab37 input=0b7474765927b925]*/
2437
{
2438
    int follow_symlinks = 0;
2439
    return posix_do_stat("lstat", path, dir_fd, follow_symlinks);
inline
           
posix_do_stat too costly to inline (cost=530, threshold=250) 
os_lstat_impl
inline
           
posix_do_stat will not be inlined into os_lstat_impl 
os_lstat_impl
inline
           
posix_do_stat too costly to inline (cost=500, threshold=250) 
os_lstat
inline
           
posix_do_stat will not be inlined into os_lstat 
os_lstat
2440
}
2441

2442

2443
/*[clinic input]
2444
os.access -> bool
2445

2446
    path: path_t
2447
        Path to be tested; can be string or bytes
2448

2449
    mode: int
2450
        Operating-system mode bitfield.  Can be F_OK to test existence,
2451
        or the inclusive-OR of R_OK, W_OK, and X_OK.
2452

2453
    *
2454

2455
    dir_fd : dir_fd(requires='faccessat') = None
2456
        If not None, it should be a file descriptor open to a directory,
2457
        and path should be relative; path will then be relative to that
2458
        directory.
2459

2460
    effective_ids: bool = False
2461
        If True, access will use the effective uid/gid instead of
2462
        the real uid/gid.
2463

2464
    follow_symlinks: bool = True
2465
        If False, and the last element of the path is a symbolic link,
2466
        access will examine the symbolic link itself instead of the file
2467
        the link points to.
2468

2469
Use the real uid/gid to test for access to a path.
2470

2471
{parameters}
2472
dir_fd, effective_ids, and follow_symlinks may not be implemented
2473
  on your platform.  If they are unavailable, using them will raise a
2474
  NotImplementedError.
2475

2476
Note that most operations will use the effective uid/gid, therefore this
2477
  routine can be used in a suid/sgid environment to test if the invoking user
2478
  has the specified access to the path.
2479

2480
[clinic start generated code]*/
2481

2482
static int
2483
os_access_impl(PyObject *module, path_t *path, int mode, int dir_fd,
2484
               int effective_ids, int follow_symlinks)
2485
/*[clinic end generated code: output=cf84158bc90b1a77 input=8e8c3a6ba791fee3]*/
2486
{
2487
    int return_value;
2488

2489
#ifdef MS_WINDOWS
2490
    DWORD attr;
2491
#else
2492
    int result;
2493
#endif
2494

2495
#ifndef HAVE_FACCESSAT
2496
    if (follow_symlinks_specified("access", follow_symlinks))
2497
        return -1;
2498

2499
    if (effective_ids) {
2500
        argument_unavailable_error("access", "effective_ids");
2501
        return -1;
2502
    }
2503
#endif
2504

2505
#ifdef MS_WINDOWS
2506
    Py_BEGIN_ALLOW_THREADS
2507
    attr = GetFileAttributesW(path->wide);
2508
    Py_END_ALLOW_THREADS
2509

2510
    /*
2511
     * Access is possible if
2512
     *   * we didn't get a -1, and
2513
     *     * write access wasn't requested,
2514
     *     * or the file isn't read-only,
2515
     *     * or it's a directory.
2516
     * (Directories cannot be read-only on Windows.)
2517
    */
2518
    return_value = (attr != INVALID_FILE_ATTRIBUTES) &&
2519
            (!(mode & 2) ||
2520
            !(attr & FILE_ATTRIBUTE_READONLY) ||
2521
            (attr & FILE_ATTRIBUTE_DIRECTORY));
2522
#else
2523

2524
    Py_BEGIN_ALLOW_THREADS
inline
    
PyEval_SaveThread will not be inlined into os_access_impl because its definition is unavailable 
os_access_impl
2525
#ifdef HAVE_FACCESSAT
2526
    if ((dir_fd != DEFAULT_DIR_FD) ||
2527
        effective_ids ||
2528
        !follow_symlinks) {
2529
        int flags = 0;
2530
        if (!follow_symlinks)
2531
            flags |= AT_SYMLINK_NOFOLLOW;
2532
        if (effective_ids)
2533
            flags |= AT_EACCESS;
2534
        result = faccessat(dir_fd, path->narrow, mode, flags);
inline
                 
faccessat will not be inlined into os_access_impl because its definition is unavailable 
os_access_impl
2535
    }
2536
    else
2537
#endif
2538
        result = access(path->narrow, mode);
inline
                 
access will not be inlined into os_access_impl because its definition is unavailable 
os_access_impl
gvn
                              
load of type i8* not eliminated because it is clobbered by call 
os_access_impl
gvn
                              
load of type i8* not eliminated because it is clobbered by call 
os_access
2539
    Py_END_ALLOW_THREADS
inline
    
PyEval_RestoreThread will not be inlined into os_access_impl because its definition is unavailable 
os_access_impl
2540
    return_value = !result;
2541
#endif
2542

2543
    return return_value;
2544
}
2545

2546
#ifndef F_OK
2547
#define F_OK 0
2548
#endif
2549
#ifndef R_OK
2550
#define R_OK 4
2551
#endif
2552
#ifndef W_OK
2553
#define W_OK 2
2554
#endif
2555
#ifndef X_OK
2556
#define X_OK 1
2557
#endif
2558

2559

2560
#ifdef HAVE_TTYNAME
2561
/*[clinic input]
2562
os.ttyname -> DecodeFSDefault
2563

2564
    fd: int
2565
        Integer file descriptor handle.
2566

2567
    /
2568

2569
Return the name of the terminal device connected to 'fd'.
2570
[clinic start generated code]*/
2571

2572
static char *
2573
os_ttyname_impl(PyObject *module, int fd)
2574
/*[clinic end generated code: output=ed16ad216d813591 input=5f72ca83e76b3b45]*/
2575
{
2576
    char *ret;
2577

2578
    ret = ttyname(fd);
inline
          
ttyname will not be inlined into os_ttyname_impl because its definition is unavailable 
os_ttyname_impl
2579
    if (ret == NULL)
2580
        posix_error();
inline
        
posix_error can be inlined into os_ttyname_impl with cost=10 (threshold=375) 
os_ttyname_impl
inline
        
posix_error inlined into os_ttyname_impl 
os_ttyname_impl
2581
    return ret;
2582
}
2583
#endif
2584

2585
#ifdef HAVE_CTERMID
2586
/*[clinic input]
2587
os.ctermid
2588

2589
Return the name of the controlling terminal for this process.
2590
[clinic start generated code]*/
2591

2592
static PyObject *
2593
os_ctermid_impl(PyObject *module)
2594
/*[clinic end generated code: output=02f017e6c9e620db input=3b87fdd52556382d]*/
2595
{
2596
    char *ret;
2597
    char buffer[L_ctermid];
2598

2599
#ifdef USE_CTERMID_R
2600
    ret = ctermid_r(buffer);
2601
#else
2602
    ret = ctermid(buffer);
inline
          
ctermid will not be inlined into os_ctermid_impl because its definition is unavailable 
os_ctermid_impl
2603
#endif
2604
    if (ret == NULL)
2605
        return posix_error();
inline
               
posix_error can be inlined into os_ctermid_impl with cost=10 (threshold=375) 
os_ctermid_impl
inline
               
posix_error inlined into os_ctermid_impl 
os_ctermid_impl
2606
    return PyUnicode_DecodeFSDefault(buffer);
inline
           
PyUnicode_DecodeFSDefault will not be inlined into os_ctermid_impl because its definition is unavailable 
os_ctermid_impl
2607
}
2608
#endif /* HAVE_CTERMID */
2609

2610

2611
/*[clinic input]
2612
os.chdir
2613

2614
    path: path_t(allow_fd='PATH_HAVE_FCHDIR')
2615

2616
Change the current working directory to the specified path.
2617

2618
path may always be specified as a string.
2619
On some platforms, path may also be specified as an open file descriptor.
2620
  If this functionality is unavailable, using it raises an exception.
2621
[clinic start generated code]*/
2622

2623
static PyObject *
2624
os_chdir_impl(PyObject *module, path_t *path)
2625
/*[clinic end generated code: output=3be6400eee26eaae input=1a4a15b4d12cb15d]*/
2626
{
2627
    int result;
2628

2629
    Py_BEGIN_ALLOW_THREADS
inline
    
PyEval_SaveThread will not be inlined into os_chdir_impl because its definition is unavailable 
os_chdir_impl
2630
#ifdef MS_WINDOWS
2631
    /* on unix, success = 0, on windows, success = !0 */
2632
    result = !win32_wchdir(path->wide);
2633
#else
2634
#ifdef HAVE_FCHDIR
2635
    if (path->fd != -1)
gvn
              
load of type i32 not eliminated because it is clobbered by call 
os_chdir_impl
gvn
              
load of type i32 not eliminated in favor of store because it is clobbered by call 
os_chdir
2636
        result = fchdir(path->fd);
inline
                 
fchdir will not be inlined into os_chdir_impl because its definition is unavailable 
os_chdir_impl
2637
    else
2638
#endif
2639
        result = chdir(path->narrow);
inline
                 
chdir will not be inlined into os_chdir_impl because its definition is unavailable 
os_chdir_impl
gvn
                             
load of type i8* not eliminated because it is clobbered by call 
os_chdir_impl
gvn
                             
load of type i8* not eliminated because it is clobbered by call 
os_chdir
2640
#endif
2641
    Py_END_ALLOW_THREADS
inline
    
PyEval_RestoreThread will not be inlined into os_chdir_impl because its definition is unavailable 
os_chdir_impl
2642

2643
    if (result) {
2644
        return path_error(path);
inline
               
path_error can be inlined into os_chdir_impl with cost=10 (threshold=375) 
os_chdir_impl
inline
               
path_error inlined into os_chdir_impl 
os_chdir_impl
2645
    }
2646

2647
    Py_RETURN_NONE;
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_chdir_impl
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_chdir
2648
}
2649

2650

2651
#ifdef HAVE_FCHDIR
2652
/*[clinic input]
2653
os.fchdir
2654

2655
    fd: fildes
2656

2657
Change to the directory of the given file descriptor.
2658

2659
fd must be opened on a directory, not a file.
2660
Equivalent to os.chdir(fd).
2661

2662
[clinic start generated code]*/
2663

2664
static PyObject *
2665
os_fchdir_impl(PyObject *module, int fd)
2666
/*[clinic end generated code: output=42e064ec4dc00ab0 input=18e816479a2fa985]*/
2667
{
2668
    return posix_fildes_fd(fd, fchdir);
inline
           
posix_fildes_fd can be inlined into os_fchdir_impl with cost=-150 (threshold=250) 
os_fchdir_impl
inline
           
posix_fildes_fd inlined into os_fchdir_impl 
os_fchdir_impl
2669
}
2670
#endif /* HAVE_FCHDIR */
2671

2672

2673
/*[clinic input]
2674
os.chmod
2675

2676
    path: path_t(allow_fd='PATH_HAVE_FCHMOD')
2677
        Path to be modified.  May always be specified as a str or bytes.
2678
        On some platforms, path may also be specified as an open file descriptor.
2679
        If this functionality is unavailable, using it raises an exception.
2680

2681
    mode: int
2682
        Operating-system mode bitfield.
2683

2684
    *
2685

2686
    dir_fd : dir_fd(requires='fchmodat') = None
2687
        If not None, it should be a file descriptor open to a directory,
2688
        and path should be relative; path will then be relative to that
2689
        directory.
2690

2691
    follow_symlinks: bool = True
2692
        If False, and the last element of the path is a symbolic link,
2693
        chmod will modify the symbolic link itself instead of the file
2694
        the link points to.
2695

2696
Change the access permissions of a file.
2697

2698
It is an error to use dir_fd or follow_symlinks when specifying path as
2699
  an open file descriptor.
2700
dir_fd and follow_symlinks may not be implemented on your platform.
2701
  If they are unavailable, using them will raise a NotImplementedError.
2702

2703
[clinic start generated code]*/
2704

2705
static PyObject *
2706
os_chmod_impl(PyObject *module, path_t *path, int mode, int dir_fd,
2707
              int follow_symlinks)
2708
/*[clinic end generated code: output=5cf6a94915cc7bff input=7f1618e5e15cc196]*/
2709
{
2710
    int result;
2711

2712
#ifdef MS_WINDOWS
2713
    DWORD attr;
2714
#endif
2715

2716
#ifdef HAVE_FCHMODAT
2717
    int fchmodat_nofollow_unsupported = 0;
2718
#endif
2719

2720
#if !(defined(HAVE_FCHMODAT) || defined(HAVE_LCHMOD))
2721
    if (follow_symlinks_specified("chmod", follow_symlinks))
2722
        return NULL;
2723
#endif
2724

2725
#ifdef MS_WINDOWS
2726
    Py_BEGIN_ALLOW_THREADS
2727
    attr = GetFileAttributesW(path->wide);
2728
    if (attr == INVALID_FILE_ATTRIBUTES)
2729
        result = 0;
2730
    else {
2731
        if (mode & _S_IWRITE)
2732
            attr &= ~FILE_ATTRIBUTE_READONLY;
2733
        else
2734
            attr |= FILE_ATTRIBUTE_READONLY;
2735
        result = SetFileAttributesW(path->wide, attr);
2736
    }
2737
    Py_END_ALLOW_THREADS
2738

2739
    if (!result) {
2740
        return path_error(path);
2741
    }
2742
#else /* MS_WINDOWS */
2743
    Py_BEGIN_ALLOW_THREADS
inline
    
PyEval_SaveThread will not be inlined into os_chmod_impl because its definition is unavailable 
os_chmod_impl
2744
#ifdef HAVE_FCHMOD
2745
    if (path->fd != -1)
gvn
              
load of type i32 not eliminated because it is clobbered by call 
os_chmod_impl
gvn
              
load of type i32 not eliminated in favor of store because it is clobbered by call 
os_chmod
2746
        result = fchmod(path->fd, mode);
inline
                 
fchmod will not be inlined into os_chmod_impl because its definition is unavailable 
os_chmod_impl
2747
    else
2748
#endif
2749
#ifdef HAVE_LCHMOD
2750
    if ((!follow_symlinks) && (dir_fd == DEFAULT_DIR_FD))
2751
        result = lchmod(path->narrow, mode);
2752
    else
2753
#endif
2754
#ifdef HAVE_FCHMODAT
2755
    if ((dir_fd != DEFAULT_DIR_FD) || !follow_symlinks) {
2756
        /*
2757
         * fchmodat() doesn't currently support AT_SYMLINK_NOFOLLOW!
2758
         * The documentation specifically shows how to use it,
2759
         * and then says it isn't implemented yet.
2760
         * (true on linux with glibc 2.15, and openindiana 3.x)
2761
         *
2762
         * Once it is supported, os.chmod will automatically
2763
         * support dir_fd and follow_symlinks=False.  (Hopefully.)
2764
         * Until then, we need to be careful what exception we raise.
2765
         */
2766
        result = fchmodat(dir_fd, path->narrow, mode,
inline
                 
fchmodat will not be inlined into os_chmod_impl because its definition is unavailable 
os_chmod_impl
2767
                          follow_symlinks ? 0 : AT_SYMLINK_NOFOLLOW);
2768
        /*
2769
         * But wait!  We can't throw the exception without allowing threads,
2770
         * and we can't do that in this nested scope.  (Macro trickery, sigh.)
2771
         */
2772
        fchmodat_nofollow_unsupported =
2773
                         result &&
2774
                         ((errno == ENOTSUP) || (errno == EOPNOTSUPP)) &&
inline
                           
__errno_location will not be inlined into os_chmod_impl because its definition is unavailable 
os_chmod_impl
2775
                         !follow_symlinks;
2776
    }
2777
    else
2778
#endif
2779
        result = chmod(path->narrow, mode);
inline
                 
chmod will not be inlined into os_chmod_impl because its definition is unavailable 
os_chmod_impl
gvn
                             
load of type i8* not eliminated because it is clobbered by call 
os_chmod_impl
gvn
                             
load of type i8* not eliminated because it is clobbered by call 
os_chmod
2780
    Py_END_ALLOW_THREADS
inline
    
PyEval_RestoreThread will not be inlined into os_chmod_impl because its definition is unavailable 
os_chmod_impl
2781

2782
    if (result) {
2783
#ifdef HAVE_FCHMODAT
2784
        if (fchmodat_nofollow_unsupported) {
2785
            if (dir_fd != DEFAULT_DIR_FD)
2786
                dir_fd_and_follow_symlinks_invalid("chmod",
inline
                
dir_fd_and_follow_symlinks_invalid can be inlined into os_chmod_impl with cost=-14970 (threshold=250) 
os_chmod_impl
inline
                
dir_fd_and_follow_symlinks_invalid inlined into os_chmod_impl 
os_chmod_impl
2787
                                                   dir_fd, follow_symlinks);
2788
            else
2789
                follow_symlinks_specified("chmod", follow_symlinks);
inline
                
follow_symlinks_specified can be inlined into os_chmod_impl with cost=-14960 (threshold=250) 
os_chmod_impl
inline
                
follow_symlinks_specified inlined into os_chmod_impl 
os_chmod_impl
2790
        }
2791
        else
2792
#endif
2793
        return path_error(path);
inline
               
path_error can be inlined into os_chmod_impl with cost=10 (threshold=375) 
os_chmod_impl
inline
               
path_error inlined into os_chmod_impl 
os_chmod_impl
2794
    }
2795
#endif
2796

2797
    Py_RETURN_NONE;
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_chmod_impl
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_chmod
2798
}
2799

2800

2801
#ifdef HAVE_FCHMOD
2802
/*[clinic input]
2803
os.fchmod
2804

2805
    fd: int
2806
    mode: int
2807

2808
Change the access permissions of the file given by file descriptor fd.
2809

2810
Equivalent to os.chmod(fd, mode).
2811
[clinic start generated code]*/
2812

2813
static PyObject *
2814
os_fchmod_impl(PyObject *module, int fd, int mode)
2815
/*[clinic end generated code: output=afd9bc05b4e426b3 input=8ab11975ca01ee5b]*/
2816
{
2817
    int res;
2818
    int async_err = 0;
2819

2820
    do {
loop-vectorize
    
loop not vectorized: loop control flow is not understood by vectorizer 
os_fchmod
loop-vectorize
    
loop not vectorized 
os_fchmod
2821
        Py_BEGIN_ALLOW_THREADS
inline
        
PyEval_SaveThread will not be inlined into os_fchmod_impl because its definition is unavailable 
os_fchmod_impl
2822
        res = fchmod(fd, mode);
inline
              
fchmod will not be inlined into os_fchmod_impl because its definition is unavailable 
os_fchmod_impl
2823
        Py_END_ALLOW_THREADS
inline
        
PyEval_RestoreThread will not be inlined into os_fchmod_impl because its definition is unavailable 
os_fchmod_impl
2824
    } while (res != 0 && errno == EINTR && !(async_err = PyErr_CheckSignals()));
inline
                         
__errno_location will not be inlined into os_fchmod_impl because its definition is unavailable 
os_fchmod_impl
inline
                                                         
PyErr_CheckSignals will not be inlined into os_fchmod_impl because its definition is unavailable 
os_fchmod_impl
2825
    if (res != 0)
2826
        return (!async_err) ? posix_error() : NULL;
inline
                              
posix_error can be inlined into os_fchmod_impl with cost=10 (threshold=375) 
os_fchmod_impl
inline
                              
posix_error inlined into os_fchmod_impl 
os_fchmod_impl
2827

2828
    Py_RETURN_NONE;
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_fchmod_impl
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_fchmod
2829
}
2830
#endif /* HAVE_FCHMOD */
2831

2832

2833
#ifdef HAVE_LCHMOD
2834
/*[clinic input]
2835
os.lchmod
2836

2837
    path: path_t
2838
    mode: int
2839

2840
Change the access permissions of a file, without following symbolic links.
2841

2842
If path is a symlink, this affects the link itself rather than the target.
2843
Equivalent to chmod(path, mode, follow_symlinks=False)."
2844
[clinic start generated code]*/
2845

2846
static PyObject *
2847
os_lchmod_impl(PyObject *module, path_t *path, int mode)
2848
/*[clinic end generated code: output=082344022b51a1d5 input=90c5663c7465d24f]*/
2849
{
2850
    int res;
2851
    Py_BEGIN_ALLOW_THREADS
2852
    res = lchmod(path->narrow, mode);
2853
    Py_END_ALLOW_THREADS
2854
    if (res < 0) {
2855
        path_error(path);
2856
        return NULL;
2857
    }
2858
    Py_RETURN_NONE;
2859
}
2860
#endif /* HAVE_LCHMOD */
2861

2862

2863
#ifdef HAVE_CHFLAGS
2864
/*[clinic input]
2865
os.chflags
2866

2867
    path: path_t
2868
    flags: unsigned_long(bitwise=True)
2869
    follow_symlinks: bool=True
2870

2871
Set file flags.
2872

2873
If follow_symlinks is False, and the last element of the path is a symbolic
2874
  link, chflags will change flags on the symbolic link itself instead of the
2875
  file the link points to.
2876
follow_symlinks may not be implemented on your platform.  If it is
2877
unavailable, using it will raise a NotImplementedError.
2878

2879
[clinic start generated code]*/
2880

2881
static PyObject *
2882
os_chflags_impl(PyObject *module, path_t *path, unsigned long flags,
2883
                int follow_symlinks)
2884
/*[clinic end generated code: output=85571c6737661ce9 input=0327e29feb876236]*/
2885
{
2886
    int result;
2887

2888
#ifndef HAVE_LCHFLAGS
2889
    if (follow_symlinks_specified("chflags", follow_symlinks))
2890
        return NULL;
2891
#endif
2892

2893
    Py_BEGIN_ALLOW_THREADS
2894
#ifdef HAVE_LCHFLAGS
2895
    if (!follow_symlinks)
2896
        result = lchflags(path->narrow, flags);
2897
    else
2898
#endif
2899
        result = chflags(path->narrow, flags);
2900
    Py_END_ALLOW_THREADS
2901

2902
    if (result)
2903
        return path_error(path);
2904

2905
    Py_RETURN_NONE;
2906
}
2907
#endif /* HAVE_CHFLAGS */
2908

2909

2910
#ifdef HAVE_LCHFLAGS
2911
/*[clinic input]
2912
os.lchflags
2913

2914
    path: path_t
2915
    flags: unsigned_long(bitwise=True)
2916

2917
Set file flags.
2918

2919
This function will not follow symbolic links.
2920
Equivalent to chflags(path, flags, follow_symlinks=False).
2921
[clinic start generated code]*/
2922

2923
static PyObject *
2924
os_lchflags_impl(PyObject *module, path_t *path, unsigned long flags)
2925
/*[clinic end generated code: output=30ae958695c07316 input=f9f82ea8b585ca9d]*/
2926
{
2927
    int res;
2928
    Py_BEGIN_ALLOW_THREADS
2929
    res = lchflags(path->narrow, flags);
2930
    Py_END_ALLOW_THREADS
2931
    if (res < 0) {
2932
        return path_error(path);
2933
    }
2934
    Py_RETURN_NONE;
2935
}
2936
#endif /* HAVE_LCHFLAGS */
2937

2938

2939
#ifdef HAVE_CHROOT
2940
/*[clinic input]
2941
os.chroot
2942
    path: path_t
2943

2944
Change root directory to path.
2945

2946
[clinic start generated code]*/
2947

2948
static PyObject *
2949
os_chroot_impl(PyObject *module, path_t *path)
2950
/*[clinic end generated code: output=de80befc763a4475 input=14822965652c3dc3]*/
2951
{
2952
    int res;
2953
    Py_BEGIN_ALLOW_THREADS
inline
    
PyEval_SaveThread will not be inlined into os_chroot_impl because its definition is unavailable 
os_chroot_impl
2954
    res = chroot(path->narrow);
inline
          
chroot will not be inlined into os_chroot_impl because its definition is unavailable 
os_chroot_impl
gvn
                       
load of type i8* not eliminated because it is clobbered by call 
os_chroot_impl
gvn
                       
load of type i8* not eliminated because it is clobbered by call 
os_chroot
2955
    Py_END_ALLOW_THREADS
inline
    
PyEval_RestoreThread will not be inlined into os_chroot_impl because its definition is unavailable 
os_chroot_impl
2956
    if (res < 0)
2957
        return path_error(path);
inline
               
path_error can be inlined into os_chroot_impl with cost=10 (threshold=375) 
os_chroot_impl
inline
               
path_error inlined into os_chroot_impl 
os_chroot_impl
2958
    Py_RETURN_NONE;
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_chroot_impl
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_chroot
2959
}
2960
#endif /* HAVE_CHROOT */
2961

2962

2963
#ifdef HAVE_FSYNC
2964
/*[clinic input]
2965
os.fsync
2966

2967
    fd: fildes
2968

2969
Force write of fd to disk.
2970
[clinic start generated code]*/
2971

2972
static PyObject *
2973
os_fsync_impl(PyObject *module, int fd)
2974
/*[clinic end generated code: output=4a10d773f52b3584 input=21c3645c056967f2]*/
2975
{
2976
    return posix_fildes_fd(fd, fsync);
inline
           
posix_fildes_fd can be inlined into os_fsync_impl with cost=-150 (threshold=250) 
os_fsync_impl
inline
           
posix_fildes_fd inlined into os_fsync_impl 
os_fsync_impl
2977
}
2978
#endif /* HAVE_FSYNC */
2979

2980

2981
#ifdef HAVE_SYNC
2982
/*[clinic input]
2983
os.sync
2984

2985
Force write of everything to disk.
2986
[clinic start generated code]*/
2987

2988
static PyObject *
2989
os_sync_impl(PyObject *module)
2990
/*[clinic end generated code: output=2796b1f0818cd71c input=84749fe5e9b404ff]*/
2991
{
2992
    Py_BEGIN_ALLOW_THREADS
inline
    
PyEval_SaveThread will not be inlined into os_sync_impl because its definition is unavailable 
os_sync_impl
2993
    sync();
inline
    
sync will not be inlined into os_sync_impl because its definition is unavailable 
os_sync_impl
2994
    Py_END_ALLOW_THREADS
inline
    
PyEval_RestoreThread will not be inlined into os_sync_impl because its definition is unavailable 
os_sync_impl
2995
    Py_RETURN_NONE;
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_sync_impl
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_sync
2996
}
2997
#endif /* HAVE_SYNC */
2998

2999

3000
#ifdef HAVE_FDATASYNC
3001
#ifdef __hpux
3002
extern int fdatasync(int); /* On HP-UX, in libc but not in unistd.h */
3003
#endif
3004

3005
/*[clinic input]
3006
os.fdatasync
3007

3008
    fd: fildes
3009

3010
Force write of fd to disk without forcing update of metadata.
3011
[clinic start generated code]*/
3012

3013
static PyObject *
3014
os_fdatasync_impl(PyObject *module, int fd)
3015
/*[clinic end generated code: output=b4b9698b5d7e26dd input=bc74791ee54dd291]*/
3016
{
3017
    return posix_fildes_fd(fd, fdatasync);
inline
           
posix_fildes_fd can be inlined into os_fdatasync_impl with cost=-15150 (threshold=250) 
os_fdatasync_impl
inline
           
posix_fildes_fd inlined into os_fdatasync_impl 
os_fdatasync_impl
3018
}
3019
#endif /* HAVE_FDATASYNC */
3020

3021

3022
#ifdef HAVE_CHOWN
3023
/*[clinic input]
3024
os.chown
3025

3026
    path : path_t(allow_fd='PATH_HAVE_FCHOWN')
3027
        Path to be examined; can be string, bytes, or open-file-descriptor int.
3028

3029
    uid: uid_t
3030

3031
    gid: gid_t
3032

3033
    *
3034

3035
    dir_fd : dir_fd(requires='fchownat') = None
3036
        If not None, it should be a file descriptor open to a directory,
3037
        and path should be relative; path will then be relative to that
3038
        directory.
3039

3040
    follow_symlinks: bool = True
3041
        If False, and the last element of the path is a symbolic link,
3042
        stat will examine the symbolic link itself instead of the file
3043
        the link points to.
3044

3045
Change the owner and group id of path to the numeric uid and gid.\
3046

3047
path may always be specified as a string.
3048
On some platforms, path may also be specified as an open file descriptor.
3049
  If this functionality is unavailable, using it raises an exception.
3050
If dir_fd is not None, it should be a file descriptor open to a directory,
3051
  and path should be relative; path will then be relative to that directory.
3052
If follow_symlinks is False, and the last element of the path is a symbolic
3053
  link, chown will modify the symbolic link itself instead of the file the
3054
  link points to.
3055
It is an error to use dir_fd or follow_symlinks when specifying path as
3056
  an open file descriptor.
3057
dir_fd and follow_symlinks may not be implemented on your platform.
3058
  If they are unavailable, using them will raise a NotImplementedError.
3059

3060
[clinic start generated code]*/
3061

3062
static PyObject *
3063
os_chown_impl(PyObject *module, path_t *path, uid_t uid, gid_t gid,
3064
              int dir_fd, int follow_symlinks)
3065
/*[clinic end generated code: output=4beadab0db5f70cd input=a61cc35574814d5d]*/
3066
{
3067
    int result;
3068

3069
#if !(defined(HAVE_LCHOWN) || defined(HAVE_FCHOWNAT))
3070
    if (follow_symlinks_specified("chown", follow_symlinks))
3071
        return NULL;
3072
#endif
3073
    if (dir_fd_and_fd_invalid("chown", dir_fd, path->fd) ||
inline
        
dir_fd_and_fd_invalid can be inlined into os_chown_impl with cost=25 (threshold=250) 
os_chown_impl
inline
        
dir_fd_and_fd_invalid inlined into os_chown_impl 
os_chown_impl
gvn
                                                     
load of type i32 not eliminated in favor of store because it is clobbered by call 
os_chown
3074
        fd_and_follow_symlinks_invalid("chown", path->fd, follow_symlinks))
inline
        
fd_and_follow_symlinks_invalid can be inlined into os_chown_impl with cost=25 (threshold=250) 
os_chown_impl
inline
        
fd_and_follow_symlinks_invalid inlined into os_chown_impl 
os_chown_impl
gvn
                                                      
load of type i32 eliminated in favor of load 
os_chown_impl
3075
        return NULL;
3076

3077
#ifdef __APPLE__
3078
    /*
3079
     * This is for Mac OS X 10.3, which doesn't have lchown.
3080
     * (But we still have an lchown symbol because of weak-linking.)
3081
     * It doesn't have fchownat either.  So there's no possibility
3082
     * of a graceful failover.
3083
     */
3084
    if ((!follow_symlinks) && (lchown == NULL)) {
3085
        follow_symlinks_specified("chown", follow_symlinks);
3086
        return NULL;
3087
    }
3088
#endif
3089

3090
    Py_BEGIN_ALLOW_THREADS
inline
    
PyEval_SaveThread will not be inlined into os_chown_impl because its definition is unavailable 
os_chown_impl
3091
#ifdef HAVE_FCHOWN
3092
    if (path->fd != -1)
gvn
              
load of type i32 not eliminated in favor of load because it is clobbered by call 
os_chown_impl
gvn
              
load of type i32 not eliminated because it is clobbered by call 
os_chown
3093
        result = fchown(path->fd, uid, gid);
inline
                 
fchown will not be inlined into os_chown_impl because its definition is unavailable 
os_chown_impl
3094
    else
3095
#endif
3096
#ifdef HAVE_LCHOWN
3097
    if ((!follow_symlinks) && (dir_fd == DEFAULT_DIR_FD))
3098
        result = lchown(path->narrow, uid, gid);
inline
                 
lchown will not be inlined into os_chown_impl because its definition is unavailable 
os_chown_impl
gvn
                              
load of type i8* not eliminated because it is clobbered by call 
os_chown_impl
gvn
                              
load of type i8* not eliminated because it is clobbered by call 
os_chown
3099
    else
3100
#endif
3101
#ifdef HAVE_FCHOWNAT
3102
    if ((dir_fd != DEFAULT_DIR_FD) || (!follow_symlinks))
3103
        result = fchownat(dir_fd, path->narrow, uid, gid,
inline
                 
fchownat will not be inlined into os_chown_impl because its definition is unavailable 
os_chown_impl
3104
                          follow_symlinks ? 0 : AT_SYMLINK_NOFOLLOW);
3105
    else
3106
#endif
3107
        result = chown(path->narrow, uid, gid);
inline
                 
chown will not be inlined into os_chown_impl because its definition is unavailable 
os_chown_impl
3108
    Py_END_ALLOW_THREADS
inline
    
PyEval_RestoreThread will not be inlined into os_chown_impl because its definition is unavailable 
os_chown_impl
3109

3110
    if (result)
3111
        return path_error(path);
inline
               
path_error can be inlined into os_chown_impl with cost=10 (threshold=375) 
os_chown_impl
inline
               
path_error inlined into os_chown_impl 
os_chown_impl
3112

3113
    Py_RETURN_NONE;
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_chown_impl
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_chown
3114
}
3115
#endif /* HAVE_CHOWN */
3116

3117

3118
#ifdef HAVE_FCHOWN
3119
/*[clinic input]
3120
os.fchown
3121

3122
    fd: int
3123
    uid: uid_t
3124
    gid: gid_t
3125

3126
Change the owner and group id of the file specified by file descriptor.
3127

3128
Equivalent to os.chown(fd, uid, gid).
3129

3130
[clinic start generated code]*/
3131

3132
static PyObject *
3133
os_fchown_impl(PyObject *module, int fd, uid_t uid, gid_t gid)
3134
/*[clinic end generated code: output=97d21cbd5a4350a6 input=3af544ba1b13a0d7]*/
3135
{
3136
    int res;
3137
    int async_err = 0;
3138

3139
    do {
loop-vectorize
    
loop not vectorized: loop control flow is not understood by vectorizer 
os_fchown
loop-vectorize
    
loop not vectorized 
os_fchown
3140
        Py_BEGIN_ALLOW_THREADS
inline
        
PyEval_SaveThread will not be inlined into os_fchown_impl because its definition is unavailable 
os_fchown_impl
3141
        res = fchown(fd, uid, gid);
inline
              
fchown will not be inlined into os_fchown_impl because its definition is unavailable 
os_fchown_impl
3142
        Py_END_ALLOW_THREADS
inline
        
PyEval_RestoreThread will not be inlined into os_fchown_impl because its definition is unavailable 
os_fchown_impl
3143
    } while (res != 0 && errno == EINTR && !(async_err = PyErr_CheckSignals()));
inline
                         
__errno_location will not be inlined into os_fchown_impl because its definition is unavailable 
os_fchown_impl
inline
                                                         
PyErr_CheckSignals will not be inlined into os_fchown_impl because its definition is unavailable 
os_fchown_impl
3144
    if (res != 0)
3145
        return (!async_err) ? posix_error() : NULL;
inline
                              
posix_error can be inlined into os_fchown_impl with cost=10 (threshold=375) 
os_fchown_impl
inline
                              
posix_error inlined into os_fchown_impl 
os_fchown_impl
3146

3147
    Py_RETURN_NONE;
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_fchown_impl
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_fchown
3148
}
3149
#endif /* HAVE_FCHOWN */
3150

3151

3152
#ifdef HAVE_LCHOWN
3153
/*[clinic input]
3154
os.lchown
3155

3156
    path : path_t
3157
    uid: uid_t
3158
    gid: gid_t
3159

3160
Change the owner and group id of path to the numeric uid and gid.
3161

3162
This function will not follow symbolic links.
3163
Equivalent to os.chown(path, uid, gid, follow_symlinks=False).
3164
[clinic start generated code]*/
3165

3166
static PyObject *
3167
os_lchown_impl(PyObject *module, path_t *path, uid_t uid, gid_t gid)
3168
/*[clinic end generated code: output=25eaf6af412fdf2f input=b1c6014d563a7161]*/
3169
{
3170
    int res;
3171
    Py_BEGIN_ALLOW_THREADS
inline
    
PyEval_SaveThread will not be inlined into os_lchown_impl because its definition is unavailable 
os_lchown_impl
3172
    res = lchown(path->narrow, uid, gid);
inline
          
lchown will not be inlined into os_lchown_impl because its definition is unavailable 
os_lchown_impl
gvn
                       
load of type i8* not eliminated because it is clobbered by call 
os_lchown_impl
gvn
                       
load of type i8* not eliminated because it is clobbered by call 
os_lchown
3173
    Py_END_ALLOW_THREADS
inline
    
PyEval_RestoreThread will not be inlined into os_lchown_impl because its definition is unavailable 
os_lchown_impl
3174
    if (res < 0) {
3175
        return path_error(path);
inline
               
path_error can be inlined into os_lchown_impl with cost=10 (threshold=375) 
os_lchown_impl
inline
               
path_error inlined into os_lchown_impl 
os_lchown_impl
3176
    }
3177
    Py_RETURN_NONE;
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_lchown_impl
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_lchown
3178
}
3179
#endif /* HAVE_LCHOWN */
3180

3181

3182
static PyObject *
3183
posix_getcwd(int use_bytes)
3184
{
3185
    char *buf, *tmpbuf;
3186
    char *cwd;
3187
    const size_t chunk = 1024;
3188
    size_t buflen = 0;
3189
    PyObject *obj;
3190

3191
#ifdef MS_WINDOWS
3192
    if (!use_bytes) {
3193
        wchar_t wbuf[MAXPATHLEN];
3194
        wchar_t *wbuf2 = wbuf;
3195
        PyObject *resobj;
3196
        DWORD len;
3197
        Py_BEGIN_ALLOW_THREADS
3198
        len = GetCurrentDirectoryW(Py_ARRAY_LENGTH(wbuf), wbuf);
3199
        /* If the buffer is large enough, len does not include the
3200
           terminating \0. If the buffer is too small, len includes
3201
           the space needed for the terminator. */
3202
        if (len >= Py_ARRAY_LENGTH(wbuf)) {
3203
            wbuf2 = PyMem_RawMalloc(len * sizeof(wchar_t));
3204
            if (wbuf2)
3205
                len = GetCurrentDirectoryW(len, wbuf2);
3206
        }
3207
        Py_END_ALLOW_THREADS
3208
        if (!wbuf2) {
3209
            PyErr_NoMemory();
3210
            return NULL;
3211
        }
3212
        if (!len) {
3213
            if (wbuf2 != wbuf)
3214
                PyMem_RawFree(wbuf2);
3215
            return PyErr_SetFromWindowsErr(0);
3216
        }
3217
        resobj = PyUnicode_FromWideChar(wbuf2, len);
3218
        if (wbuf2 != wbuf)
3219
            PyMem_RawFree(wbuf2);
3220
        return resobj;
3221
    }
3222

3223
    if (win32_warn_bytes_api())
3224
        return NULL;
3225
#endif
3226

3227
    buf = cwd = NULL;
3228
    Py_BEGIN_ALLOW_THREADS
inline
    
PyEval_SaveThread will not be inlined into posix_getcwd because its definition is unavailable 
posix_getcwd
3229
    do {
loop-vectorize
    
loop not vectorized: loop control flow is not understood by vectorizer 
posix_getcwd
loop-vectorize
    
loop not vectorized 
posix_getcwd
3230
        buflen += chunk;
3231
#ifdef MS_WINDOWS
3232
        if (buflen > INT_MAX) {
3233
            PyErr_NoMemory();
3234
            break;
3235
        }
3236
#endif
3237
        tmpbuf = PyMem_RawRealloc(buf, buflen);
inline
                 
PyMem_RawRealloc will not be inlined into posix_getcwd because its definition is unavailable 
posix_getcwd
3238
        if (tmpbuf == NULL)
3239
            break;
3240

3241
        buf = tmpbuf;
3242
#ifdef MS_WINDOWS
3243
        cwd = getcwd(buf, (int)buflen);
3244
#else
3245
        cwd = getcwd(buf, buflen);
inline
              
getcwd will not be inlined into posix_getcwd because its definition is unavailable 
posix_getcwd
3246
#endif
3247
    } while (cwd == NULL && errno == ERANGE);
inline
                            
__errno_location will not be inlined into posix_getcwd because its definition is unavailable 
posix_getcwd
3248
    Py_END_ALLOW_THREADS
inline
    
PyEval_RestoreThread will not be inlined into posix_getcwd because its definition is unavailable 
posix_getcwd
3249

3250
    if (cwd == NULL) {
3251
        PyMem_RawFree(buf);
inline
        
PyMem_RawFree will not be inlined into posix_getcwd because its definition is unavailable 
posix_getcwd
3252
        return posix_error();
inline
               
posix_error can be inlined into posix_getcwd with cost=10 (threshold=375) 
posix_getcwd
inline
               
posix_error inlined into posix_getcwd 
posix_getcwd
3253
    }
3254

3255
    if (use_bytes)
3256
        obj = PyBytes_FromStringAndSize(buf, strlen(buf));
inline
                                             
strlen will not be inlined into posix_getcwd because its definition is unavailable 
posix_getcwd
inline
              
PyBytes_FromStringAndSize will not be inlined into posix_getcwd because its definition is unavailable 
posix_getcwd
3257
    else
3258
        obj = PyUnicode_DecodeFSDefault(buf);
inline
              
PyUnicode_DecodeFSDefault will not be inlined into posix_getcwd because its definition is unavailable 
posix_getcwd
3259
    PyMem_RawFree(buf);
inline
    
PyMem_RawFree will not be inlined into posix_getcwd because its definition is unavailable 
posix_getcwd
3260

3261
    return obj;
3262
}
3263

3264

3265
/*[clinic input]
3266
os.getcwd
3267

3268
Return a unicode string representing the current working directory.
3269
[clinic start generated code]*/
3270

3271
static PyObject *
3272
os_getcwd_impl(PyObject *module)
3273
/*[clinic end generated code: output=21badfae2ea99ddc input=f069211bb70e3d39]*/
3274
{
3275
    return posix_getcwd(0);
inline
           
posix_getcwd too costly to inline (cost=360, threshold=250) 
os_getcwd_impl
inline
           
posix_getcwd will not be inlined into os_getcwd_impl 
os_getcwd_impl
inline
           
posix_getcwd too costly to inline (cost=360, threshold=250) 
os_getcwd
inline
           
posix_getcwd will not be inlined into os_getcwd 
os_getcwd
3276
}
3277

3278

3279
/*[clinic input]
3280
os.getcwdb
3281

3282
Return a bytes string representing the current working directory.
3283
[clinic start generated code]*/
3284

3285
static PyObject *
3286
os_getcwdb_impl(PyObject *module)
3287
/*[clinic end generated code: output=3dd47909480e4824 input=f6f6a378dad3d9cb]*/
3288
{
3289
    return posix_getcwd(1);
inline
           
posix_getcwd too costly to inline (cost=400, threshold=250) 
os_getcwdb_impl
inline
           
posix_getcwd will not be inlined into os_getcwdb_impl 
os_getcwdb_impl
inline
           
posix_getcwd too costly to inline (cost=400, threshold=250) 
os_getcwdb
inline
           
posix_getcwd will not be inlined into os_getcwdb 
os_getcwdb
3290
}
3291

3292

3293
#if ((!defined(HAVE_LINK)) && defined(MS_WINDOWS))
3294
#define HAVE_LINK 1
3295
#endif
3296

3297
#ifdef HAVE_LINK
3298
/*[clinic input]
3299

3300
os.link
3301

3302
    src : path_t
3303
    dst : path_t
3304
    *
3305
    src_dir_fd : dir_fd = None
3306
    dst_dir_fd : dir_fd = None
3307
    follow_symlinks: bool = True
3308

3309
Create a hard link to a file.
3310

3311
If either src_dir_fd or dst_dir_fd is not None, it should be a file
3312
  descriptor open to a directory, and the respective path string (src or dst)
3313
  should be relative; the path will then be relative to that directory.
3314
If follow_symlinks is False, and the last element of src is a symbolic
3315
  link, link will create a link to the symbolic link itself instead of the
3316
  file the link points to.
3317
src_dir_fd, dst_dir_fd, and follow_symlinks may not be implemented on your
3318
  platform.  If they are unavailable, using them will raise a
3319
  NotImplementedError.
3320
[clinic start generated code]*/
3321

3322
static PyObject *
3323
os_link_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
3324
             int dst_dir_fd, int follow_symlinks)
3325
/*[clinic end generated code: output=7f00f6007fd5269a input=b0095ebbcbaa7e04]*/
3326
{
3327
#ifdef MS_WINDOWS
3328
    BOOL result = FALSE;
3329
#else
3330
    int result;
3331
#endif
3332

3333
#ifndef HAVE_LINKAT
3334
    if ((src_dir_fd != DEFAULT_DIR_FD) || (dst_dir_fd != DEFAULT_DIR_FD)) {
3335
        argument_unavailable_error("link", "src_dir_fd and dst_dir_fd");
3336
        return NULL;
3337
    }
3338
#endif
3339

3340
#ifndef MS_WINDOWS
3341
    if ((src->narrow && dst->wide) || (src->wide && dst->narrow)) {
gvn
              
load of type i8* not eliminated because it is clobbered by call 
os_link
gvn
                             
load of type i32* not eliminated because it is clobbered by call 
os_link
gvn
                                            
load of type i32* not eliminated because it is clobbered by call 
os_link
gvn
                                                         
load of type i8* not eliminated because it is clobbered by call 
os_link
3342
        PyErr_SetString(PyExc_NotImplementedError,
inline
        
PyErr_SetString will not be inlined into os_link_impl because its definition is unavailable 
os_link_impl
gvn
                        
load of type %struct._object* not eliminated because it is clobbered by call 
os_link
3343
                        "link: src and dst must be the same type");
3344
        return NULL;
3345
    }
3346
#endif
3347

3348
#ifdef MS_WINDOWS
3349
    Py_BEGIN_ALLOW_THREADS
3350
    result = CreateHardLinkW(dst->wide, src->wide, NULL);
3351
    Py_END_ALLOW_THREADS
3352

3353
    if (!result)
3354
        return path_error2(src, dst);
3355
#else
3356
    Py_BEGIN_ALLOW_THREADS
inline
    
PyEval_SaveThread will not be inlined into os_link_impl because its definition is unavailable 
os_link_impl
3357
#ifdef HAVE_LINKAT
3358
    if ((src_dir_fd != DEFAULT_DIR_FD) ||
3359
        (dst_dir_fd != DEFAULT_DIR_FD) ||
3360
        (!follow_symlinks))
3361
        result = linkat(src_dir_fd, src->narrow,
inline
                 
linkat will not be inlined into os_link_impl because its definition is unavailable 
os_link_impl
3362
            dst_dir_fd, dst->narrow,
3363
            follow_symlinks ? AT_SYMLINK_FOLLOW : 0);
3364
    else
3365
#endif /* HAVE_LINKAT */
3366
        result = link(src->narrow, dst->narrow);
inline
                 
link will not be inlined into os_link_impl because its definition is unavailable 
os_link_impl
gvn
                           
load of type i8* not eliminated in favor of load because it is clobbered by call 
os_link_impl
gvn
                                        
load of type i8* not eliminated because it is clobbered by call 
os_link_impl
gvn
                           
load of type i8* not eliminated in favor of load because it is clobbered by call 
os_link
gvn
                                        
load of type i8* not eliminated in favor of load because it is clobbered by call 
os_link
3367
    Py_END_ALLOW_THREADS
inline
    
PyEval_RestoreThread will not be inlined into os_link_impl because its definition is unavailable 
os_link_impl
3368

3369
    if (result)
3370
        return path_error2(src, dst);
inline
               
path_error2 can be inlined into os_link_impl with cost=10 (threshold=375) 
os_link_impl
inline
               
path_error2 inlined into os_link_impl 
os_link_impl
3371
#endif /* MS_WINDOWS */
3372

3373
    Py_RETURN_NONE;
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_link_impl
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_link
3374
}
3375
#endif
3376

3377

3378
#if defined(MS_WINDOWS) && !defined(HAVE_OPENDIR)
3379
static PyObject *
3380
_listdir_windows_no_opendir(path_t *path, PyObject *list)
3381
{
3382
    PyObject *v;
3383
    HANDLE hFindFile = INVALID_HANDLE_VALUE;
3384
    BOOL result;
3385
    wchar_t namebuf[MAX_PATH+4]; /* Overallocate for "\*.*" */
3386
    /* only claim to have space for MAX_PATH */
3387
    Py_ssize_t len = Py_ARRAY_LENGTH(namebuf)-4;
3388
    wchar_t *wnamebuf = NULL;
3389

3390
    WIN32_FIND_DATAW wFileData;
3391
    const wchar_t *po_wchars;
3392

3393
    if (!path->wide) { /* Default arg: "." */
3394
        po_wchars = L".";
3395
        len = 1;
3396
    } else {
3397
        po_wchars = path->wide;
3398
        len = wcslen(path->wide);
3399
    }
3400
    /* The +5 is so we can append "\\*.*\0" */
3401
    wnamebuf = PyMem_New(wchar_t, len + 5);
3402
    if (!wnamebuf) {
3403
        PyErr_NoMemory();
3404
        goto exit;
3405
    }
3406
    wcscpy(wnamebuf, po_wchars);
3407
    if (len > 0) {
3408
        wchar_t wch = wnamebuf[len-1];
3409
        if (wch != SEP && wch != ALTSEP && wch != L':')
3410
            wnamebuf[len++] = SEP;
3411
        wcscpy(wnamebuf + len, L"*.*");
3412
    }
3413
    if ((list = PyList_New(0)) == NULL) {
3414
        goto exit;
3415
    }
3416
    Py_BEGIN_ALLOW_THREADS
3417
    hFindFile = FindFirstFileW(wnamebuf, &wFileData);
3418
    Py_END_ALLOW_THREADS
3419
    if (hFindFile == INVALID_HANDLE_VALUE) {
3420
        int error = GetLastError();
3421
        if (error == ERROR_FILE_NOT_FOUND)
3422
            goto exit;
3423
        Py_DECREF(list);
3424
        list = path_error(path);
3425
        goto exit;
3426
    }
3427
    do {
3428
        /* Skip over . and .. */
3429
        if (wcscmp(wFileData.cFileName, L".") != 0 &&
3430
            wcscmp(wFileData.cFileName, L"..") != 0) {
3431
            v = PyUnicode_FromWideChar(wFileData.cFileName,
3432
                                       wcslen(wFileData.cFileName));
3433
            if (path->narrow && v) {
3434
                Py_SETREF(v, PyUnicode_EncodeFSDefault(v));
3435
            }
3436
            if (v == NULL) {
3437
                Py_DECREF(list);
3438
                list = NULL;
3439
                break;
3440
            }
3441
            if (PyList_Append(list, v) != 0) {
3442
                Py_DECREF(v);
3443
                Py_DECREF(list);
3444
                list = NULL;
3445
                break;
3446
            }
3447
            Py_DECREF(v);
3448
        }
3449
        Py_BEGIN_ALLOW_THREADS
3450
        result = FindNextFileW(hFindFile, &wFileData);
3451
        Py_END_ALLOW_THREADS
3452
        /* FindNextFile sets error to ERROR_NO_MORE_FILES if
3453
           it got to the end of the directory. */
3454
        if (!result && GetLastError() != ERROR_NO_MORE_FILES) {
3455
            Py_DECREF(list);
3456
            list = path_error(path);
3457
            goto exit;
3458
        }
3459
    } while (result == TRUE);
3460

3461
exit:
3462
    if (hFindFile != INVALID_HANDLE_VALUE) {
3463
        if (FindClose(hFindFile) == FALSE) {
3464
            if (list != NULL) {
3465
                Py_DECREF(list);
3466
                list = path_error(path);
3467
            }
3468
        }
3469
    }
3470
    PyMem_Free(wnamebuf);
3471

3472
    return list;
3473
}  /* end of _listdir_windows_no_opendir */
3474

3475
#else  /* thus POSIX, ie: not (MS_WINDOWS and not HAVE_OPENDIR) */
3476

3477
static PyObject *
3478
_posix_listdir(path_t *path, PyObject *list)
3479
{
3480
    PyObject *v;
3481
    DIR *dirp = NULL;
3482
    struct dirent *ep;
3483
    int return_str; /* if false, return bytes */
3484
#ifdef HAVE_FDOPENDIR
3485
    int fd = -1;
3486
#endif
3487

3488
    errno = 0;
inline
    
__errno_location will not be inlined into _posix_listdir because its definition is unavailable 
_posix_listdir
3489
#ifdef HAVE_FDOPENDIR
3490
    if (path->fd != -1) {
gvn
              
load of type i32 not eliminated because it is clobbered by store 
_posix_listdir
gvn
              
load of type i32 not eliminated because it is clobbered by store 
os_listdir_impl
gvn
              
load of type i32 not eliminated in favor of store because it is clobbered by store 
os_listdir
3491
        /* closedir() closes the FD, so we duplicate it */
3492
        fd = _Py_dup(path->fd);
inline
             
_Py_dup will not be inlined into _posix_listdir because its definition is unavailable 
_posix_listdir
3493
        if (fd == -1)
3494
            return NULL;
3495

3496
        return_str = 1;
3497

3498
        Py_BEGIN_ALLOW_THREADS
inline
        
PyEval_SaveThread will not be inlined into _posix_listdir because its definition is unavailable 
_posix_listdir
3499
        dirp = fdopendir(fd);
inline
               
fdopendir will not be inlined into _posix_listdir because its definition is unavailable 
_posix_listdir
3500
        Py_END_ALLOW_THREADS
inline
        
PyEval_RestoreThread will not be inlined into _posix_listdir because its definition is unavailable 
_posix_listdir
3501
    }
3502
    else
3503
#endif
3504
    {
3505
        const char *name;
3506
        if (path->narrow) {
gvn
                  
load of type i8* not eliminated because it is clobbered by call 
os_listdir
3507
            name = path->narrow;
3508
            /* only return bytes if they specified a bytes object */
3509
            return_str = !(PyBytes_Check(path->object));
gvn
                           
load of type %struct._object* not eliminated because it is clobbered by call 
os_listdir
3510
        }
3511
        else {
3512
            name = ".";
3513
            return_str = 1;
3514
        }
3515

3516
        Py_BEGIN_ALLOW_THREADS
inline
        
PyEval_SaveThread will not be inlined into _posix_listdir because its definition is unavailable 
_posix_listdir
3517
        dirp = opendir(name);
inline
               
opendir will not be inlined into _posix_listdir because its definition is unavailable 
_posix_listdir
3518
        Py_END_ALLOW_THREADS
inline
        
PyEval_RestoreThread will not be inlined into _posix_listdir because its definition is unavailable 
_posix_listdir
3519
    }
3520

3521
    if (dirp == NULL) {
3522
        list = path_error(path);
inline
               
path_error can be inlined into _posix_listdir with cost=10 (threshold=375) 
_posix_listdir
inline
               
path_error inlined into _posix_listdir 
_posix_listdir
3523
#ifdef HAVE_FDOPENDIR
3524
        if (fd != -1) {
3525
            Py_BEGIN_ALLOW_THREADS
inline
            
PyEval_SaveThread will not be inlined into _posix_listdir because its definition is unavailable 
_posix_listdir
3526
            close(fd);
inline
            
close will not be inlined into _posix_listdir because its definition is unavailable 
_posix_listdir
3527
            Py_END_ALLOW_THREADS
inline
            
PyEval_RestoreThread will not be inlined into _posix_listdir because its definition is unavailable 
_posix_listdir
3528
        }
3529
#endif
3530
        goto exit;
3531
    }
3532
    if ((list = PyList_New(0)) == NULL) {
inline
                
PyList_New will not be inlined into _posix_listdir because its definition is unavailable 
_posix_listdir
3533
        goto exit;
3534
    }
3535
    for (;;) {
loop-vectorize
    
loop not vectorized: loop control flow is not understood by vectorizer 
os_listdir
loop-vectorize
    
loop not vectorized 
os_listdir
3536
        errno = 0;
3537
        Py_BEGIN_ALLOW_THREADS
inline
        
PyEval_SaveThread will not be inlined into _posix_listdir because its definition is unavailable 
_posix_listdir
3538
        ep = readdir(dirp);
inline
             
readdir64 will not be inlined into _posix_listdir because its definition is unavailable 
_posix_listdir
3539
        Py_END_ALLOW_THREADS
inline
        
PyEval_RestoreThread will not be inlined into _posix_listdir because its definition is unavailable 
_posix_listdir
3540
        if (ep == NULL) {
3541
            if (errno == 0) {
gvn
                
load of type i32 not eliminated because it is clobbered by call 
_posix_listdir
gvn
                
load of type i32 not eliminated because it is clobbered by call 
os_listdir_impl
gvn
                
load of type i32 not eliminated because it is clobbered by call 
os_listdir
3542
                break;
3543
            } else {
3544
                Py_DECREF(list);
gvn
                
load of type i64 not eliminated because it is clobbered by call 
_posix_listdir
gvn
                
load of type i64 not eliminated because it is clobbered by call 
os_listdir_impl
gvn
                
load of type i64 not eliminated because it is clobbered by call 
os_listdir
3545
                list = path_error(path);
inline
                       
path_error can be inlined into _posix_listdir with cost=10 (threshold=375) 
_posix_listdir
inline
                       
path_error inlined into _posix_listdir 
_posix_listdir
3546
                goto exit;
3547
            }
3548
        }
3549
        if (ep->d_name[0] == '.' &&
3550
            (NAMLEN(ep) == 1 ||
inline
             
strlen will not be inlined into _posix_listdir because its definition is unavailable 
_posix_listdir
3551
             (ep->d_name[1] == '.' && NAMLEN(ep) == 2)))
3552
            continue;
3553
        if (return_str)
licm
            
hosting icmp 
_posix_listdir
3554
            v = PyUnicode_DecodeFSDefaultAndSize(ep->d_name, NAMLEN(ep));
inline
                                                             
strlen will not be inlined into _posix_listdir because its definition is unavailable 
_posix_listdir
inline
                
PyUnicode_DecodeFSDefaultAndSize will not be inlined into _posix_listdir because its definition is unavailable 
_posix_listdir
3555
        else
3556
            v = PyBytes_FromStringAndSize(ep->d_name, NAMLEN(ep));
inline
                
PyBytes_FromStringAndSize will not be inlined into _posix_listdir because its definition is unavailable 
_posix_listdir
3557
        if (v == NULL) {
3558
            Py_CLEAR(list);
gvn
            
load of type i64 not eliminated because it is clobbered by call 
_posix_listdir
gvn
            
load of type i64 not eliminated because it is clobbered by call 
os_listdir_impl
gvn
            
load of type i64 not eliminated because it is clobbered by call 
os_listdir
3559
            break;
3560
        }
3561
        if (PyList_Append(list, v) != 0) {
inline
            
PyList_Append will not be inlined into _posix_listdir because its definition is unavailable 
_posix_listdir
3562
            Py_DECREF(v);
gvn
            
load of type i64 not eliminated because it is clobbered by call 
_posix_listdir
gvn
            
load of type i64 not eliminated because it is clobbered by call 
os_listdir_impl
gvn
            
load of type i64 not eliminated because it is clobbered by call 
os_listdir
3563
            Py_CLEAR(list);
gvn
            
load of type i64 not eliminated because it is clobbered by call 
_posix_listdir
gvn
            
load of type i64 not eliminated because it is clobbered by call 
os_listdir_impl
gvn
            
load of type i64 not eliminated because it is clobbered by call 
os_listdir
3564
            break;
3565
        }
3566
        Py_DECREF(v);
gvn
        
load of type %struct._typeobject* not eliminated because it is clobbered by call 
_posix_listdir
gvn
        
load of type %struct._typeobject* not eliminated because it is clobbered by call 
os_listdir_impl
gvn
        
load of type %struct._typeobject* not eliminated because it is clobbered by call 
os_listdir
3567
    }
3568

3569
exit:
3570
    if (dirp != NULL) {
3571
        Py_BEGIN_ALLOW_THREADS
inline
        
PyEval_SaveThread will not be inlined into _posix_listdir because its definition is unavailable 
_posix_listdir
3572
#ifdef HAVE_FDOPENDIR
3573
        if (fd > -1)
3574
            rewinddir(dirp);
inline
            
rewinddir will not be inlined into _posix_listdir because its definition is unavailable 
_posix_listdir
3575
#endif
3576
        closedir(dirp);
inline
        
closedir will not be inlined into _posix_listdir because its definition is unavailable 
_posix_listdir
3577
        Py_END_ALLOW_THREADS
inline
        
PyEval_RestoreThread will not be inlined into _posix_listdir because its definition is unavailable 
_posix_listdir
3578
    }
3579

3580
    return list;
3581
}  /* end of _posix_listdir */
3582
#endif  /* which OS */
3583

3584

3585
/*[clinic input]
3586
os.listdir
3587

3588
    path : path_t(nullable=True, allow_fd='PATH_HAVE_FDOPENDIR') = None
3589

3590
Return a list containing the names of the files in the directory.
3591

3592
path can be specified as either str or bytes.  If path is bytes,
3593
  the filenames returned will also be bytes; in all other circumstances
3594
  the filenames returned will be str.
3595
If path is None, uses the path='.'.
3596
On some platforms, path may also be specified as an open file descriptor;\
3597
  the file descriptor must refer to a directory.
3598
  If this functionality is unavailable, using it raises NotImplementedError.
3599

3600
The list is in arbitrary order.  It does not include the special
3601
entries '.' and '..' even if they are present in the directory.
3602

3603

3604
[clinic start generated code]*/
3605

3606
static PyObject *
3607
os_listdir_impl(PyObject *module, path_t *path)
3608
/*[clinic end generated code: output=293045673fcd1a75 input=09e300416e3cd729]*/
3609
{
3610
#if defined(MS_WINDOWS) && !defined(HAVE_OPENDIR)
3611
    return _listdir_windows_no_opendir(path, NULL);
3612
#else
3613
    return _posix_listdir(path, NULL);
inline
           
_posix_listdir can be inlined into os_listdir_impl with cost=-13225 (threshold=250) 
os_listdir_impl
inline
           
_posix_listdir inlined into os_listdir_impl 
os_listdir_impl
3614
#endif
3615
}
3616

3617
#ifdef MS_WINDOWS
3618
/* A helper function for abspath on win32 */
3619
/*[clinic input]
3620
os._getfullpathname
3621

3622
    path: path_t
3623
    /
3624

3625
[clinic start generated code]*/
3626

3627
static PyObject *
3628
os__getfullpathname_impl(PyObject *module, path_t *path)
3629
/*[clinic end generated code: output=bb8679d56845bc9b input=332ed537c29d0a3e]*/
3630
{
3631
    wchar_t woutbuf[MAX_PATH], *woutbufp = woutbuf;
3632
    wchar_t *wtemp;
3633
    DWORD result;
3634
    PyObject *v;
3635

3636
    result = GetFullPathNameW(path->wide,
3637
                              Py_ARRAY_LENGTH(woutbuf),
3638
                              woutbuf, &wtemp);
3639
    if (result > Py_ARRAY_LENGTH(woutbuf)) {
3640
        woutbufp = PyMem_New(wchar_t, result);
3641
        if (!woutbufp)
3642
            return PyErr_NoMemory();
3643
        result = GetFullPathNameW(path->wide, result, woutbufp, &wtemp);
3644
    }
3645
    if (result) {
3646
        v = PyUnicode_FromWideChar(woutbufp, wcslen(woutbufp));
3647
        if (path->narrow)
3648
            Py_SETREF(v, PyUnicode_EncodeFSDefault(v));
3649
    } else
3650
        v = win32_error_object("GetFullPathNameW", path->object);
3651
    if (woutbufp != woutbuf)
3652
        PyMem_Free(woutbufp);
3653
    return v;
3654
}
3655

3656

3657
/*[clinic input]
3658
os._getfinalpathname
3659

3660
    path: unicode
3661
    /
3662

3663
A helper function for samepath on windows.
3664
[clinic start generated code]*/
3665

3666
static PyObject *
3667
os__getfinalpathname_impl(PyObject *module, PyObject *path)
3668
/*[clinic end generated code: output=9bd78d0e52782e75 input=71d5e89334891bf4]*/
3669
{
3670
    HANDLE hFile;
3671
    int buf_size;
3672
    wchar_t *target_path;
3673
    int result_length;
3674
    PyObject *result;
3675
    const wchar_t *path_wchar;
3676

3677
    path_wchar = PyUnicode_AsUnicode(path);
3678
    if (path_wchar == NULL)
3679
        return NULL;
3680

3681
    hFile = CreateFileW(
3682
        path_wchar,
3683
        0, /* desired access */
3684
        0, /* share mode */
3685
        NULL, /* security attributes */
3686
        OPEN_EXISTING,
3687
        /* FILE_FLAG_BACKUP_SEMANTICS is required to open a directory */
3688
        FILE_FLAG_BACKUP_SEMANTICS,
3689
        NULL);
3690

3691
    if(hFile == INVALID_HANDLE_VALUE)
3692
        return win32_error_object("CreateFileW", path);
3693

3694
    /* We have a good handle to the target, use it to determine the
3695
       target path name. */
3696
    buf_size = GetFinalPathNameByHandleW(hFile, 0, 0, VOLUME_NAME_NT);
3697

3698
    if(!buf_size)
3699
        return win32_error_object("GetFinalPathNameByHandle", path);
3700

3701
    target_path = PyMem_New(wchar_t, buf_size+1);
3702
    if(!target_path)
3703
        return PyErr_NoMemory();
3704

3705
    result_length = GetFinalPathNameByHandleW(hFile, target_path,
3706
                                              buf_size, VOLUME_NAME_DOS);
3707
    if(!result_length)
3708
        return win32_error_object("GetFinalPathNamyByHandle", path);
3709

3710
    if(!CloseHandle(hFile))
3711
        return win32_error_object("CloseHandle", path);
3712

3713
    target_path[result_length] = 0;
3714
    result = PyUnicode_FromWideChar(target_path, result_length);
3715
    PyMem_Free(target_path);
3716
    return result;
3717
}
3718

3719
/*[clinic input]
3720
os._isdir
3721

3722
    path: path_t
3723
    /
3724

3725
Return true if the pathname refers to an existing directory.
3726
[clinic start generated code]*/
3727

3728
static PyObject *
3729
os__isdir_impl(PyObject *module, path_t *path)
3730
/*[clinic end generated code: output=75f56f32720836cb input=5e0800149c0ad95f]*/
3731
{
3732
    DWORD attributes;
3733

3734
    Py_BEGIN_ALLOW_THREADS
3735
    attributes = GetFileAttributesW(path->wide);
3736
    Py_END_ALLOW_THREADS
3737

3738
    if (attributes == INVALID_FILE_ATTRIBUTES)
3739
        Py_RETURN_FALSE;
3740

3741
    if (attributes & FILE_ATTRIBUTE_DIRECTORY)
3742
        Py_RETURN_TRUE;
3743
    else
3744
        Py_RETURN_FALSE;
3745
}
3746

3747

3748
/*[clinic input]
3749
os._getvolumepathname
3750

3751
    path: unicode
3752

3753
A helper function for ismount on Win32.
3754
[clinic start generated code]*/
3755

3756
static PyObject *
3757
os__getvolumepathname_impl(PyObject *module, PyObject *path)
3758
/*[clinic end generated code: output=cbdcbd1059ceef4c input=7eacadc40acbda6b]*/
3759
{
3760
    PyObject *result;
3761
    const wchar_t *path_wchar;
3762
    wchar_t *mountpath=NULL;
3763
    size_t buflen;
3764
    BOOL ret;
3765

3766
    path_wchar = PyUnicode_AsUnicodeAndSize(path, &buflen);
3767
    if (path_wchar == NULL)
3768
        return NULL;
3769
    buflen += 1;
3770

3771
    /* Volume path should be shorter than entire path */
3772
    buflen = Py_MAX(buflen, MAX_PATH);
3773

3774
    if (buflen > DWORD_MAX) {
3775
        PyErr_SetString(PyExc_OverflowError, "path too long");
3776
        return NULL;
3777
    }
3778

3779
    mountpath = PyMem_New(wchar_t, buflen);
3780
    if (mountpath == NULL)
3781
        return PyErr_NoMemory();
3782

3783
    Py_BEGIN_ALLOW_THREADS
3784
    ret = GetVolumePathNameW(path_wchar, mountpath,
3785
                             Py_SAFE_DOWNCAST(buflen, size_t, DWORD));
3786
    Py_END_ALLOW_THREADS
3787

3788
    if (!ret) {
3789
        result = win32_error_object("_getvolumepathname", path);
3790
        goto exit;
3791
    }
3792
    result = PyUnicode_FromWideChar(mountpath, wcslen(mountpath));
3793

3794
exit:
3795
    PyMem_Free(mountpath);
3796
    return result;
3797
}
3798

3799
#endif /* MS_WINDOWS */
3800

3801

3802
/*[clinic input]
3803
os.mkdir
3804

3805
    path : path_t
3806

3807
    mode: int = 0o777
3808

3809
    *
3810

3811
    dir_fd : dir_fd(requires='mkdirat') = None
3812

3813
# "mkdir(path, mode=0o777, *, dir_fd=None)\n\n\
3814

3815
Create a directory.
3816

3817
If dir_fd is not None, it should be a file descriptor open to a directory,
3818
  and path should be relative; path will then be relative to that directory.
3819
dir_fd may not be implemented on your platform.
3820
  If it is unavailable, using it will raise a NotImplementedError.
3821

3822
The mode argument is ignored on Windows.
3823
[clinic start generated code]*/
3824

3825
static PyObject *
3826
os_mkdir_impl(PyObject *module, path_t *path, int mode, int dir_fd)
3827
/*[clinic end generated code: output=a70446903abe821f input=e965f68377e9b1ce]*/
3828
{
3829
    int result;
3830

3831
#ifdef MS_WINDOWS
3832
    Py_BEGIN_ALLOW_THREADS
3833
    result = CreateDirectoryW(path->wide, NULL);
3834
    Py_END_ALLOW_THREADS
3835

3836
    if (!result)
3837
        return path_error(path);
3838
#else
3839
    Py_BEGIN_ALLOW_THREADS
inline
    
PyEval_SaveThread will not be inlined into os_mkdir_impl because its definition is unavailable 
os_mkdir_impl
3840
#if HAVE_MKDIRAT
3841
    if (dir_fd != DEFAULT_DIR_FD)
3842
        result = mkdirat(dir_fd, path->narrow, mode);
inline
                 
mkdirat will not be inlined into os_mkdir_impl because its definition is unavailable 
os_mkdir_impl
gvn
                                       
load of type i8* not eliminated because it is clobbered by call 
os_mkdir_impl
gvn
                                       
load of type i8* not eliminated because it is clobbered by call 
os_mkdir
3843
    else
3844
#endif
3845
#if ( defined(__WATCOMC__) || defined(PYCC_VACPP) ) && !defined(__QNX__)
3846
        result = mkdir(path->narrow);
3847
#else
3848
        result = mkdir(path->narrow, mode);
inline
                 
mkdir will not be inlined into os_mkdir_impl because its definition is unavailable 
os_mkdir_impl
3849
#endif
3850
    Py_END_ALLOW_THREADS
inline
    
PyEval_RestoreThread will not be inlined into os_mkdir_impl because its definition is unavailable 
os_mkdir_impl
3851
    if (result < 0)
3852
        return path_error(path);
inline
               
path_error can be inlined into os_mkdir_impl with cost=10 (threshold=375) 
os_mkdir_impl
inline
               
path_error inlined into os_mkdir_impl 
os_mkdir_impl
3853
#endif /* MS_WINDOWS */
3854
    Py_RETURN_NONE;
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_mkdir_impl
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_mkdir
3855
}
3856

3857

3858
/* sys/resource.h is needed for at least: wait3(), wait4(), broken nice. */
3859
#if defined(HAVE_SYS_RESOURCE_H)
3860
#include <sys/resource.h>
3861
#endif
3862

3863

3864
#ifdef HAVE_NICE
3865
/*[clinic input]
3866
os.nice
3867

3868
    increment: int
3869
    /
3870

3871
Add increment to the priority of process and return the new priority.
3872
[clinic start generated code]*/
3873

3874
static PyObject *
3875
os_nice_impl(PyObject *module, int increment)
3876
/*[clinic end generated code: output=9dad8a9da8109943 input=864be2d402a21da2]*/
3877
{
3878
    int value;
3879

3880
    /* There are two flavours of 'nice': one that returns the new
3881
       priority (as required by almost all standards out there) and the
3882
       Linux/FreeBSD/BSDI one, which returns '0' on success and advices
3883
       the use of getpriority() to get the new priority.
3884

3885
       If we are of the nice family that returns the new priority, we
3886
       need to clear errno before the call, and check if errno is filled
3887
       before calling posix_error() on a returnvalue of -1, because the
3888
       -1 may be the actual new priority! */
3889

3890
    errno = 0;
inline
    
__errno_location will not be inlined into os_nice_impl because its definition is unavailable 
os_nice_impl
3891
    value = nice(increment);
inline
            
nice will not be inlined into os_nice_impl because its definition is unavailable 
os_nice_impl
3892
#if defined(HAVE_BROKEN_NICE) && defined(HAVE_GETPRIORITY)
3893
    if (value == 0)
3894
        value = getpriority(PRIO_PROCESS, 0);
3895
#endif
3896
    if (value == -1 && errno != 0)
gvn
                       
load of type i32 not eliminated in favor of store because it is clobbered by call 
os_nice_impl
gvn
                       
load of type i32 not eliminated in favor of store because it is clobbered by call 
os_nice
3897
        /* either nice() or getpriority() returned an error */
3898
        return posix_error();
inline
               
posix_error can be inlined into os_nice_impl with cost=10 (threshold=375) 
os_nice_impl
inline
               
posix_error inlined into os_nice_impl 
os_nice_impl
3899
    return PyLong_FromLong((long) value);
inline
           
PyLong_FromLong will not be inlined into os_nice_impl because its definition is unavailable 
os_nice_impl
3900
}
3901
#endif /* HAVE_NICE */
3902

3903

3904
#ifdef HAVE_GETPRIORITY
3905
/*[clinic input]
3906
os.getpriority
3907

3908
    which: int
3909
    who: int
3910

3911
Return program scheduling priority.
3912
[clinic start generated code]*/
3913

3914
static PyObject *
3915
os_getpriority_impl(PyObject *module, int which, int who)
3916
/*[clinic end generated code: output=c41b7b63c7420228 input=9be615d40e2544ef]*/
3917
{
3918
    int retval;
3919

3920
    errno = 0;
inline
    
__errno_location will not be inlined into os_getpriority_impl because its definition is unavailable 
os_getpriority_impl
3921
    retval = getpriority(which, who);
inline
             
getpriority will not be inlined into os_getpriority_impl because its definition is unavailable 
os_getpriority_impl
3922
    if (errno != 0)
gvn
        
load of type i32 not eliminated in favor of store because it is clobbered by call 
os_getpriority_impl
gvn
        
load of type i32 not eliminated in favor of store because it is clobbered by call 
os_getpriority
3923
        return posix_error();
inline
               
posix_error can be inlined into os_getpriority_impl with cost=10 (threshold=375) 
os_getpriority_impl
inline
               
posix_error inlined into os_getpriority_impl 
os_getpriority_impl
3924
    return PyLong_FromLong((long)retval);
inline
           
PyLong_FromLong will not be inlined into os_getpriority_impl because its definition is unavailable 
os_getpriority_impl
3925
}
3926
#endif /* HAVE_GETPRIORITY */
3927

3928

3929
#ifdef HAVE_SETPRIORITY
3930
/*[clinic input]
3931
os.setpriority
3932

3933
    which: int
3934
    who: int
3935
    priority: int
3936

3937
Set program scheduling priority.
3938
[clinic start generated code]*/
3939

3940
static PyObject *
3941
os_setpriority_impl(PyObject *module, int which, int who, int priority)
3942
/*[clinic end generated code: output=3d910d95a7771eb2 input=710ccbf65b9dc513]*/
3943
{
3944
    int retval;
3945

3946
    retval = setpriority(which, who, priority);
inline
             
setpriority will not be inlined into os_setpriority_impl because its definition is unavailable 
os_setpriority_impl
3947
    if (retval == -1)
3948
        return posix_error();
inline
               
posix_error can be inlined into os_setpriority_impl with cost=10 (threshold=375) 
os_setpriority_impl
inline
               
posix_error inlined into os_setpriority_impl 
os_setpriority_impl
3949
    Py_RETURN_NONE;
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_setpriority_impl
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_setpriority
3950
}
3951
#endif /* HAVE_SETPRIORITY */
3952

3953

3954
static PyObject *
3955
internal_rename(path_t *src, path_t *dst, int src_dir_fd, int dst_dir_fd, int is_replace)
3956
{
3957
    const char *function_name = is_replace ? "replace" : "rename";
3958
    int dir_fd_specified;
3959

3960
#ifdef MS_WINDOWS
3961
    BOOL result;
3962
    int flags = is_replace ? MOVEFILE_REPLACE_EXISTING : 0;
3963
#else
3964
    int result;
3965
#endif
3966

3967
    dir_fd_specified = (src_dir_fd != DEFAULT_DIR_FD) ||
3968
                       (dst_dir_fd != DEFAULT_DIR_FD);
3969
#ifndef HAVE_RENAMEAT
3970
    if (dir_fd_specified) {
3971
        argument_unavailable_error(function_name, "src_dir_fd and dst_dir_fd");
3972
        return NULL;
3973
    }
3974
#endif
3975

3976
#ifdef MS_WINDOWS
3977
    Py_BEGIN_ALLOW_THREADS
3978
    result = MoveFileExW(src->wide, dst->wide, flags);
3979
    Py_END_ALLOW_THREADS
3980

3981
    if (!result)
3982
        return path_error2(src, dst);
3983

3984
#else
3985
    if ((src->narrow && dst->wide) || (src->wide && dst->narrow)) {
3986
        PyErr_Format(PyExc_ValueError,
inline
        
PyErr_Format will not be inlined into internal_rename because its definition is unavailable 
internal_rename
3987
                     "%s: src and dst must be the same type", function_name);
3988
        return NULL;
3989
    }
3990

3991
    Py_BEGIN_ALLOW_THREADS
inline
    
PyEval_SaveThread will not be inlined into internal_rename because its definition is unavailable 
internal_rename
3992
#ifdef HAVE_RENAMEAT
3993
    if (dir_fd_specified)
3994
        result = renameat(src_dir_fd, src->narrow, dst_dir_fd, dst->narrow);
inline
                 
renameat will not be inlined into internal_rename because its definition is unavailable 
internal_rename
gvn
                                                                    
load of type i8* not eliminated because it is clobbered by call 
internal_rename
gvn
                                           
load of type i8* not eliminated in favor of load because it is clobbered by call 
internal_rename
3995
    else
3996
#endif
3997
    result = rename(src->narrow, dst->narrow);
inline
             
rename will not be inlined into internal_rename because its definition is unavailable 
internal_rename
3998
    Py_END_ALLOW_THREADS
inline
    
PyEval_RestoreThread will not be inlined into internal_rename because its definition is unavailable 
internal_rename
3999

4000
    if (result)
4001
        return path_error2(src, dst);
inline
               
path_error2 can be inlined into internal_rename with cost=10 (threshold=375) 
internal_rename
inline
               
path_error2 inlined into internal_rename 
internal_rename
4002
#endif
4003
    Py_RETURN_NONE;
gvn
    
load of type i64 not eliminated because it is clobbered by call 
internal_rename
4004
}
4005

4006

4007
/*[clinic input]
4008
os.rename
4009

4010
    src : path_t
4011
    dst : path_t
4012
    *
4013
    src_dir_fd : dir_fd = None
4014
    dst_dir_fd : dir_fd = None
4015

4016
Rename a file or directory.
4017

4018
If either src_dir_fd or dst_dir_fd is not None, it should be a file
4019
  descriptor open to a directory, and the respective path string (src or dst)
4020
  should be relative; the path will then be relative to that directory.
4021
src_dir_fd and dst_dir_fd, may not be implemented on your platform.
4022
  If they are unavailable, using them will raise a NotImplementedError.
4023
[clinic start generated code]*/
4024

4025
static PyObject *
4026
os_rename_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
4027
               int dst_dir_fd)
4028
/*[clinic end generated code: output=59e803072cf41230 input=faa61c847912c850]*/
4029
{
4030
    return internal_rename(src, dst, src_dir_fd, dst_dir_fd, 0);
inline
           
internal_rename too costly to inline (cost=330, threshold=250) 
os_rename_impl
inline
           
internal_rename will not be inlined into os_rename_impl 
os_rename_impl
inline
           
internal_rename too costly to inline (cost=290, threshold=250) 
os_rename
inline
           
internal_rename will not be inlined into os_rename 
os_rename
4031
}
4032

4033

4034
/*[clinic input]
4035
os.replace = os.rename
4036

4037
Rename a file or directory, overwriting the destination.
4038

4039
If either src_dir_fd or dst_dir_fd is not None, it should be a file
4040
  descriptor open to a directory, and the respective path string (src or dst)
4041
  should be relative; the path will then be relative to that directory.
4042
src_dir_fd and dst_dir_fd, may not be implemented on your platform.
4043
  If they are unavailable, using them will raise a NotImplementedError."
4044
[clinic start generated code]*/
4045

4046
static PyObject *
4047
os_replace_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
4048
                int dst_dir_fd)
4049
/*[clinic end generated code: output=1968c02e7857422b input=25515dfb107c8421]*/
4050
{
4051
    return internal_rename(src, dst, src_dir_fd, dst_dir_fd, 1);
inline
           
internal_rename too costly to inline (cost=330, threshold=250) 
os_replace_impl
inline
           
internal_rename will not be inlined into os_replace_impl 
os_replace_impl
inline
           
internal_rename too costly to inline (cost=290, threshold=250) 
os_replace
inline
           
internal_rename will not be inlined into os_replace 
os_replace
4052
}
4053

4054

4055
/*[clinic input]
4056
os.rmdir
4057

4058
    path: path_t
4059
    *
4060
    dir_fd: dir_fd(requires='unlinkat') = None
4061

4062
Remove a directory.
4063

4064
If dir_fd is not None, it should be a file descriptor open to a directory,
4065
  and path should be relative; path will then be relative to that directory.
4066
dir_fd may not be implemented on your platform.
4067
  If it is unavailable, using it will raise a NotImplementedError.
4068
[clinic start generated code]*/
4069

4070
static PyObject *
4071
os_rmdir_impl(PyObject *module, path_t *path, int dir_fd)
4072
/*[clinic end generated code: output=080eb54f506e8301 input=38c8b375ca34a7e2]*/
4073
{
4074
    int result;
4075

4076
    Py_BEGIN_ALLOW_THREADS
inline
    
PyEval_SaveThread will not be inlined into os_rmdir_impl because its definition is unavailable 
os_rmdir_impl
4077
#ifdef MS_WINDOWS
4078
    /* Windows, success=1, UNIX, success=0 */
4079
    result = !RemoveDirectoryW(path->wide);
4080
#else
4081
#ifdef HAVE_UNLINKAT
4082
    if (dir_fd != DEFAULT_DIR_FD)
4083
        result = unlinkat(dir_fd, path->narrow, AT_REMOVEDIR);
inline
                 
unlinkat will not be inlined into os_rmdir_impl because its definition is unavailable 
os_rmdir_impl
gvn
                                        
load of type i8* not eliminated because it is clobbered by call 
os_rmdir_impl
gvn
                                        
load of type i8* not eliminated because it is clobbered by call 
os_rmdir
4084
    else
4085
#endif
4086
        result = rmdir(path->narrow);
inline
                 
rmdir will not be inlined into os_rmdir_impl because its definition is unavailable 
os_rmdir_impl
4087
#endif
4088
    Py_END_ALLOW_THREADS
inline
    
PyEval_RestoreThread will not be inlined into os_rmdir_impl because its definition is unavailable 
os_rmdir_impl
4089

4090
    if (result)
4091
        return path_error(path);
inline
               
path_error can be inlined into os_rmdir_impl with cost=10 (threshold=375) 
os_rmdir_impl
inline
               
path_error inlined into os_rmdir_impl 
os_rmdir_impl
4092

4093
    Py_RETURN_NONE;
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_rmdir_impl
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_rmdir
4094
}
4095

4096

4097
#ifdef HAVE_SYSTEM
4098
#ifdef MS_WINDOWS
4099
/*[clinic input]
4100
os.system -> long
4101

4102
    command: Py_UNICODE
4103

4104
Execute the command in a subshell.
4105
[clinic start generated code]*/
4106

4107
static long
4108
os_system_impl(PyObject *module, Py_UNICODE *command)
4109
/*[clinic end generated code: output=96c4dffee36dfb48 input=303f5ce97df606b0]*/
4110
{
4111
    long result;
4112
    Py_BEGIN_ALLOW_THREADS
4113
    _Py_BEGIN_SUPPRESS_IPH
4114
    result = _wsystem(command);
4115
    _Py_END_SUPPRESS_IPH
4116
    Py_END_ALLOW_THREADS
4117
    return result;
4118
}
4119
#else /* MS_WINDOWS */
4120
/*[clinic input]
4121
os.system -> long
4122

4123
    command: FSConverter
4124

4125
Execute the command in a subshell.
4126
[clinic start generated code]*/
4127

4128
static long
4129
os_system_impl(PyObject *module, PyObject *command)
4130
/*[clinic end generated code: output=290fc437dd4f33a0 input=86a58554ba6094af]*/
4131
{
4132
    long result;
4133
    const char *bytes = PyBytes_AsString(command);
inline
                        
PyBytes_AsString will not be inlined into os_system_impl because its definition is unavailable 
os_system_impl
4134
    Py_BEGIN_ALLOW_THREADS
inline
    
PyEval_SaveThread will not be inlined into os_system_impl because its definition is unavailable 
os_system_impl
4135
    result = system(bytes);
inline
             
system will not be inlined into os_system_impl because its definition is unavailable 
os_system_impl
4136
    Py_END_ALLOW_THREADS
inline
    
PyEval_RestoreThread will not be inlined into os_system_impl because its definition is unavailable 
os_system_impl
4137
    return result;
4138
}
4139
#endif
4140
#endif /* HAVE_SYSTEM */
4141

4142

4143
/*[clinic input]
4144
os.umask
4145

4146
    mask: int
4147
    /
4148

4149
Set the current numeric umask and return the previous umask.
4150
[clinic start generated code]*/
4151

4152
static PyObject *
4153
os_umask_impl(PyObject *module, int mask)
4154
/*[clinic end generated code: output=a2e33ce3bc1a6e33 input=ab6bfd9b24d8a7e8]*/
4155
{
4156
    int i = (int)umask(mask);
inline
                 
umask will not be inlined into os_umask_impl because its definition is unavailable 
os_umask_impl
4157
    if (i < 0)
4158
        return posix_error();
inline
               
posix_error can be inlined into os_umask_impl with cost=10 (threshold=375) 
os_umask_impl
inline
               
posix_error inlined into os_umask_impl 
os_umask_impl
4159
    return PyLong_FromLong((long)i);
inline
           
PyLong_FromLong will not be inlined into os_umask_impl because its definition is unavailable 
os_umask_impl
4160
}
4161

4162
#ifdef MS_WINDOWS
4163

4164
/* override the default DeleteFileW behavior so that directory
4165
symlinks can be removed with this function, the same as with
4166
Unix symlinks */
4167
BOOL WINAPI Py_DeleteFileW(LPCWSTR lpFileName)
4168
{
4169
    WIN32_FILE_ATTRIBUTE_DATA info;
4170
    WIN32_FIND_DATAW find_data;
4171
    HANDLE find_data_handle;
4172
    int is_directory = 0;
4173
    int is_link = 0;
4174

4175
    if (GetFileAttributesExW(lpFileName, GetFileExInfoStandard, &info)) {
4176
        is_directory = info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY;
4177

4178
        /* Get WIN32_FIND_DATA structure for the path to determine if
4179
           it is a symlink */
4180
        if(is_directory &&
4181
           info.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) {
4182
            find_data_handle = FindFirstFileW(lpFileName, &find_data);
4183

4184
            if(find_data_handle != INVALID_HANDLE_VALUE) {
4185
                /* IO_REPARSE_TAG_SYMLINK if it is a symlink and
4186
                   IO_REPARSE_TAG_MOUNT_POINT if it is a junction point. */
4187
                is_link = find_data.dwReserved0 == IO_REPARSE_TAG_SYMLINK ||
4188
                          find_data.dwReserved0 == IO_REPARSE_TAG_MOUNT_POINT;
4189
                FindClose(find_data_handle);
4190
            }
4191
        }
4192
    }
4193

4194
    if (is_directory && is_link)
4195
        return RemoveDirectoryW(lpFileName);
4196

4197
    return DeleteFileW(lpFileName);
4198
}
4199
#endif /* MS_WINDOWS */
4200

4201

4202
/*[clinic input]
4203
os.unlink
4204

4205
    path: path_t
4206
    *
4207
    dir_fd: dir_fd(requires='unlinkat')=None
4208

4209
Remove a file (same as remove()).
4210

4211
If dir_fd is not None, it should be a file descriptor open to a directory,
4212
  and path should be relative; path will then be relative to that directory.
4213
dir_fd may not be implemented on your platform.
4214
  If it is unavailable, using it will raise a NotImplementedError.
4215

4216
[clinic start generated code]*/
4217

4218
static PyObject *
4219
os_unlink_impl(PyObject *module, path_t *path, int dir_fd)
4220
/*[clinic end generated code: output=621797807b9963b1 input=d7bcde2b1b2a2552]*/
4221
{
4222
    int result;
4223

4224
    Py_BEGIN_ALLOW_THREADS
inline
    
PyEval_SaveThread will not be inlined into os_unlink_impl because its definition is unavailable 
os_unlink_impl
4225
    _Py_BEGIN_SUPPRESS_IPH
4226
#ifdef MS_WINDOWS
4227
    /* Windows, success=1, UNIX, success=0 */
4228
    result = !Py_DeleteFileW(path->wide);
4229
#else
4230
#ifdef HAVE_UNLINKAT
4231
    if (dir_fd != DEFAULT_DIR_FD)
4232
        result = unlinkat(dir_fd, path->narrow, 0);
inline
                 
unlinkat will not be inlined into os_unlink_impl because its definition is unavailable 
os_unlink_impl
gvn
                                        
load of type i8* not eliminated because it is clobbered by call 
os_unlink_impl
gvn
                                        
load of type i8* not eliminated because it is clobbered by call 
os_unlink
gvn
                                        
load of type i8* not eliminated because it is clobbered by call 
os_remove_impl
gvn
                                        
load of type i8* not eliminated because it is clobbered by call 
os_remove
4233
    else
4234
#endif /* HAVE_UNLINKAT */
4235
        result = unlink(path->narrow);
inline
                 
unlink will not be inlined into os_unlink_impl because its definition is unavailable 
os_unlink_impl
4236
#endif
4237
    _Py_END_SUPPRESS_IPH
4238
    Py_END_ALLOW_THREADS
inline
    
PyEval_RestoreThread will not be inlined into os_unlink_impl because its definition is unavailable 
os_unlink_impl
4239

4240
    if (result)
4241
        return path_error(path);
inline
               
path_error can be inlined into os_unlink_impl with cost=10 (threshold=375) 
os_unlink_impl
inline
               
path_error inlined into os_unlink_impl 
os_unlink_impl
4242

4243
    Py_RETURN_NONE;
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_unlink_impl
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_unlink
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_remove_impl
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_remove
4244
}
4245

4246

4247
/*[clinic input]
4248
os.remove = os.unlink
4249

4250
Remove a file (same as unlink()).
4251

4252
If dir_fd is not None, it should be a file descriptor open to a directory,
4253
  and path should be relative; path will then be relative to that directory.
4254
dir_fd may not be implemented on your platform.
4255
  If it is unavailable, using it will raise a NotImplementedError.
4256
[clinic start generated code]*/
4257

4258
static PyObject *
4259
os_remove_impl(PyObject *module, path_t *path, int dir_fd)
4260
/*[clinic end generated code: output=a8535b28f0068883 input=e05c5ab55cd30983]*/
4261
{
4262
    return os_unlink_impl(module, path, dir_fd);
inline
           
os_unlink_impl can be inlined into os_remove_impl with cost=-14805 (threshold=250) 
os_remove_impl
inline
           
os_unlink_impl inlined into os_remove_impl 
os_remove_impl
4263
}
4264

4265

4266
static PyStructSequence_Field uname_result_fields[] = {
4267
    {"sysname",    "operating system name"},
4268
    {"nodename",   "name of machine on network (implementation-defined)"},
4269
    {"release",    "operating system release"},
4270
    {"version",    "operating system version"},
4271
    {"machine",    "hardware identifier"},
4272
    {NULL}
4273
};
4274

4275
PyDoc_STRVAR(uname_result__doc__,
4276
"uname_result: Result from os.uname().\n\n\
4277
This object may be accessed either as a tuple of\n\
4278
  (sysname, nodename, release, version, machine),\n\
4279
or via the attributes sysname, nodename, release, version, and machine.\n\
4280
\n\
4281
See os.uname for more information.");
4282

4283
static PyStructSequence_Desc uname_result_desc = {
4284
    "uname_result", /* name */
4285
    uname_result__doc__, /* doc */
4286
    uname_result_fields,
4287
    5
4288
};
4289

4290
static PyTypeObject UnameResultType;
4291

4292

4293
#ifdef HAVE_UNAME
4294
/*[clinic input]
4295
os.uname
4296

4297
Return an object identifying the current operating system.
4298

4299
The object behaves like a named tuple with the following fields:
4300
  (sysname, nodename, release, version, machine)
4301

4302
[clinic start generated code]*/
4303

4304
static PyObject *
4305
os_uname_impl(PyObject *module)
4306
/*[clinic end generated code: output=e6a49cf1a1508a19 input=e68bd246db3043ed]*/
4307
{
4308
    struct utsname u;
4309
    int res;
4310
    PyObject *value;
4311

4312
    Py_BEGIN_ALLOW_THREADS
inline
    
PyEval_SaveThread will not be inlined into os_uname_impl because its definition is unavailable 
os_uname_impl
4313
    res = uname(&u);
inline
          
uname will not be inlined into os_uname_impl because its definition is unavailable 
os_uname_impl
4314
    Py_END_ALLOW_THREADS
inline
    
PyEval_RestoreThread will not be inlined into os_uname_impl because its definition is unavailable 
os_uname_impl
4315
    if (res < 0)
4316
        return posix_error();
inline
               
posix_error can be inlined into os_uname_impl with cost=10 (threshold=375) 
os_uname_impl
inline
               
posix_error inlined into os_uname_impl 
os_uname_impl
4317

4318
    value = PyStructSequence_New(&UnameResultType);
inline
            
PyStructSequence_New will not be inlined into os_uname_impl because its definition is unavailable 
os_uname_impl
4319
    if (value == NULL)
4320
        return NULL;
4321

4322
#define SET(i, field) \
4323
    { \
4324
    PyObject *o = PyUnicode_DecodeFSDefault(field); \
4325
    if (!o) { \
4326
        Py_DECREF(value); \
4327
        return NULL; \
4328
    } \
4329
    PyStructSequence_SET_ITEM(value, i, o); \
4330
    } \
4331

4332
    SET(0, u.sysname);
inline
    
PyUnicode_DecodeFSDefault will not be inlined into os_uname_impl because its definition is unavailable 
os_uname_impl
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_uname_impl
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_uname
4333
    SET(1, u.nodename);
inline
    
PyUnicode_DecodeFSDefault will not be inlined into os_uname_impl because its definition is unavailable 
os_uname_impl
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_uname_impl
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_uname
4334
    SET(2, u.release);
inline
    
PyUnicode_DecodeFSDefault will not be inlined into os_uname_impl because its definition is unavailable 
os_uname_impl
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_uname_impl
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_uname
4335
    SET(3, u.version);
inline
    
PyUnicode_DecodeFSDefault will not be inlined into os_uname_impl because its definition is unavailable 
os_uname_impl
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_uname_impl
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_uname
4336
    SET(4, u.machine);
inline
    
PyUnicode_DecodeFSDefault will not be inlined into os_uname_impl because its definition is unavailable 
os_uname_impl
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_uname_impl
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_uname
4337

4338
#undef SET
4339

4340
    return value;
4341
}
4342
#endif /* HAVE_UNAME */
4343

4344

4345

4346
typedef struct {
4347
    int    now;
4348
    time_t atime_s;
4349
    long   atime_ns;
4350
    time_t mtime_s;
4351
    long   mtime_ns;
4352
} utime_t;
4353

4354
/*
4355
 * these macros assume that "ut" is a pointer to a utime_t
4356
 * they also intentionally leak the declaration of a pointer named "time"
4357
 */
4358
#define UTIME_TO_TIMESPEC \
4359
    struct timespec ts[2]; \
4360
    struct timespec *time; \
4361
    if (ut->now) \
4362
        time = NULL; \
4363
    else { \
4364
        ts[0].tv_sec = ut->atime_s; \
4365
        ts[0].tv_nsec = ut->atime_ns; \
4366
        ts[1].tv_sec = ut->mtime_s; \
4367
        ts[1].tv_nsec = ut->mtime_ns; \
4368
        time = ts; \
4369
    } \
4370

4371
#define UTIME_TO_TIMEVAL \
4372
    struct timeval tv[2]; \
4373
    struct timeval *time; \
4374
    if (ut->now) \
4375
        time = NULL; \
4376
    else { \
4377
        tv[0].tv_sec = ut->atime_s; \
4378
        tv[0].tv_usec = ut->atime_ns / 1000; \
4379
        tv[1].tv_sec = ut->mtime_s; \
4380
        tv[1].tv_usec = ut->mtime_ns / 1000; \
4381
        time = tv; \
4382
    } \
4383

4384
#define UTIME_TO_UTIMBUF \
4385
    struct utimbuf u; \
4386
    struct utimbuf *time; \
4387
    if (ut->now) \
4388
        time = NULL; \
4389
    else { \
4390
        u.actime = ut->atime_s; \
4391
        u.modtime = ut->mtime_s; \
4392
        time = &u; \
4393
    }
4394

4395
#define UTIME_TO_TIME_T \
4396
    time_t timet[2]; \
4397
    time_t *time; \
4398
    if (ut->now) \
4399
        time = NULL; \
4400
    else { \
4401
        timet[0] = ut->atime_s; \
4402
        timet[1] = ut->mtime_s; \
4403
        time = timet; \
4404
    } \
4405

4406

4407
#if defined(HAVE_FUTIMESAT) || defined(HAVE_UTIMENSAT)
4408

4409
static int
4410
utime_dir_fd(utime_t *ut, int dir_fd, const char *path, int follow_symlinks)
4411
{
4412
#ifdef HAVE_UTIMENSAT
4413
    int flags = follow_symlinks ? 0 : AT_SYMLINK_NOFOLLOW;
4414
    UTIME_TO_TIMESPEC;
4415
    return utimensat(dir_fd, path, time, flags);
inline
           
utimensat will not be inlined into utime_dir_fd because its definition is unavailable 
utime_dir_fd
4416
#elif defined(HAVE_FUTIMESAT)
4417
    UTIME_TO_TIMEVAL;
4418
    /*
4419
     * follow_symlinks will never be false here;
4420
     * we only allow !follow_symlinks and dir_fd together
4421
     * if we have utimensat()
4422
     */
4423
    assert(follow_symlinks);
4424
    return futimesat(dir_fd, path, time);
4425
#endif
4426
}
4427

4428
    #define FUTIMENSAT_DIR_FD_CONVERTER dir_fd_converter
4429
#else
4430
    #define FUTIMENSAT_DIR_FD_CONVERTER dir_fd_unavailable
4431
#endif
4432

4433
#if defined(HAVE_FUTIMES) || defined(HAVE_FUTIMENS)
4434

4435
static int
4436
utime_fd(utime_t *ut, int fd)
4437
{
4438
#ifdef HAVE_FUTIMENS
4439
    UTIME_TO_TIMESPEC;
4440
    return futimens(fd, time);
inline
           
futimens will not be inlined into utime_fd because its definition is unavailable 
utime_fd
4441
#else
4442
    UTIME_TO_TIMEVAL;
4443
    return futimes(fd, time);
4444
#endif
4445
}
4446

4447
    #define PATH_UTIME_HAVE_FD 1
4448
#else
4449
    #define PATH_UTIME_HAVE_FD 0
4450
#endif
4451

4452
#if defined(HAVE_UTIMENSAT) || defined(HAVE_LUTIMES)
4453
#  define UTIME_HAVE_NOFOLLOW_SYMLINKS
4454
#endif
4455

4456
#ifdef UTIME_HAVE_NOFOLLOW_SYMLINKS
4457

4458
static int
4459
utime_nofollow_symlinks(utime_t *ut, const char *path)
4460
{
4461
#ifdef HAVE_UTIMENSAT
4462
    UTIME_TO_TIMESPEC;
4463
    return utimensat(DEFAULT_DIR_FD, path, time, AT_SYMLINK_NOFOLLOW);
inline
           
utimensat will not be inlined into utime_nofollow_symlinks because its definition is unavailable 
utime_nofollow_symlinks
4464
#else
4465
    UTIME_TO_TIMEVAL;
4466
    return lutimes(path, time);
4467
#endif
4468
}
4469

4470
#endif
4471

4472
#ifndef MS_WINDOWS
4473

4474
static int
4475
utime_default(utime_t *ut, const char *path)
4476
{
4477
#ifdef HAVE_UTIMENSAT
4478
    UTIME_TO_TIMESPEC;
4479
    return utimensat(DEFAULT_DIR_FD, path, time, 0);
inline
           
utimensat will not be inlined into utime_default because its definition is unavailable 
utime_default
4480
#elif defined(HAVE_UTIMES)
4481
    UTIME_TO_TIMEVAL;
4482
    return utimes(path, time);
4483
#elif defined(HAVE_UTIME_H)
4484
    UTIME_TO_UTIMBUF;
4485
    return utime(path, time);
4486
#else
4487
    UTIME_TO_TIME_T;
4488
    return utime(path, time);
4489
#endif
4490
}
4491

4492
#endif
4493

4494
static int
4495
split_py_long_to_s_and_ns(PyObject *py_long, time_t *s, long *ns)
4496
{
4497
    int result = 0;
4498
    PyObject *divmod;
4499
    divmod = PyNumber_Divmod(py_long, billion);
inline
             
PyNumber_Divmod will not be inlined into split_py_long_to_s_and_ns because its definition is unavailable 
split_py_long_to_s_and_ns
gvn
                                      
load of type %struct._object* not eliminated because it is clobbered by call 
os_utime_impl
gvn
                                      
load of type %struct._object* not eliminated because it is clobbered by call 
os_utime
4500
    if (!divmod)
4501
        goto exit;
4502
    *s = _PyLong_AsTime_t(PyTuple_GET_ITEM(divmod, 0));
inline
         
_PyLong_AsTime_t will not be inlined into split_py_long_to_s_and_ns because its definition is unavailable 
split_py_long_to_s_and_ns
gvn
                          
load of type %struct._object* not eliminated because it is clobbered by call 
split_py_long_to_s_and_ns
gvn
                          
load of type %struct._object* not eliminated because it is clobbered by call 
os_utime_impl
gvn
                          
load of type %struct._object* not eliminated because it is clobbered by call 
os_utime
4503
    if ((*s == -1) && PyErr_Occurred())
inline
                      
PyErr_Occurred will not be inlined into split_py_long_to_s_and_ns because its definition is unavailable 
split_py_long_to_s_and_ns
4504
        goto exit;
4505
    *ns = PyLong_AsLong(PyTuple_GET_ITEM(divmod, 1));
inline
          
PyLong_AsLong will not be inlined into split_py_long_to_s_and_ns because its definition is unavailable 
split_py_long_to_s_and_ns
gvn
                        
load of type %struct._object* not eliminated because it is clobbered by call 
split_py_long_to_s_and_ns
gvn
                        
load of type %struct._object* not eliminated because it is clobbered by call 
os_utime_impl
gvn
                        
load of type %struct._object* not eliminated because it is clobbered by call 
os_utime
4506
    if ((*ns == -1) && PyErr_Occurred())
inline
                       
PyErr_Occurred will not be inlined into split_py_long_to_s_and_ns because its definition is unavailable 
split_py_long_to_s_and_ns
4507
        goto exit;
4508

4509
    result = 1;
4510
exit:
4511
    Py_XDECREF(divmod);
gvn
    
load of type i64 not eliminated because it is clobbered by call 
split_py_long_to_s_and_ns
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_utime_impl
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_utime
4512
    return result;
4513
}
4514

4515

4516
/*[clinic input]
4517
os.utime
4518

4519
    path: path_t(allow_fd='PATH_UTIME_HAVE_FD')
4520
    times: object = NULL
4521
    *
4522
    ns: object = NULL
4523
    dir_fd: dir_fd(requires='futimensat') = None
4524
    follow_symlinks: bool=True
4525

4526
# "utime(path, times=None, *[, ns], dir_fd=None, follow_symlinks=True)\n\
4527

4528
Set the access and modified time of path.
4529

4530
path may always be specified as a string.
4531
On some platforms, path may also be specified as an open file descriptor.
4532
  If this functionality is unavailable, using it raises an exception.
4533

4534
If times is not None, it must be a tuple (atime, mtime);
4535
    atime and mtime should be expressed as float seconds since the epoch.
4536
If ns is specified, it must be a tuple (atime_ns, mtime_ns);
4537
    atime_ns and mtime_ns should be expressed as integer nanoseconds
4538
    since the epoch.
4539
If times is None and ns is unspecified, utime uses the current time.
4540
Specifying tuples for both times and ns is an error.
4541

4542
If dir_fd is not None, it should be a file descriptor open to a directory,
4543
  and path should be relative; path will then be relative to that directory.
4544
If follow_symlinks is False, and the last element of the path is a symbolic
4545
  link, utime will modify the symbolic link itself instead of the file the
4546
  link points to.
4547
It is an error to use dir_fd or follow_symlinks when specifying path
4548
  as an open file descriptor.
4549
dir_fd and follow_symlinks may not be available on your platform.
4550
  If they are unavailable, using them will raise a NotImplementedError.
4551

4552
[clinic start generated code]*/
4553

4554
static PyObject *
4555
os_utime_impl(PyObject *module, path_t *path, PyObject *times, PyObject *ns,
4556
              int dir_fd, int follow_symlinks)
4557
/*[clinic end generated code: output=cfcac69d027b82cf input=081cdc54ca685385]*/
4558
{
4559
#ifdef MS_WINDOWS
4560
    HANDLE hFile;
4561
    FILETIME atime, mtime;
4562
#else
4563
    int result;
4564
#endif
4565

4566
    PyObject *return_value = NULL;
4567
    utime_t utime;
4568

4569
    memset(&utime, 0, sizeof(utime_t));
4570

4571
    if (times && (times != Py_None) && ns) {
4572
        PyErr_SetString(PyExc_ValueError,
inline
        
PyErr_SetString will not be inlined into os_utime_impl because its definition is unavailable 
os_utime_impl
gvn
                        
load of type %struct._object* not eliminated because it is clobbered by call 
os_utime
4573
                     "utime: you may specify either 'times'"
4574
                     " or 'ns' but not both");
4575
        goto exit;
4576
    }
4577

4578
    if (times && (times != Py_None)) {
4579
        time_t a_sec, m_sec;
4580
        long a_nsec, m_nsec;
4581
        if (!PyTuple_CheckExact(times) || (PyTuple_Size(times) != 2)) {
inline
                                           
PyTuple_Size will not be inlined into os_utime_impl because its definition is unavailable 
os_utime_impl
4582
            PyErr_SetString(PyExc_TypeError,
inline
            
PyErr_SetString will not be inlined into os_utime_impl because its definition is unavailable 
os_utime_impl
gvn
                            
load of type %struct._object* not eliminated because it is clobbered by call 
os_utime_impl
gvn
                            
load of type %struct._object* not eliminated because it is clobbered by call 
os_utime
4583
                         "utime: 'times' must be either"
4584
                         " a tuple of two ints or None");
4585
            goto exit;
4586
        }
4587
        utime.now = 0;
4588
        if (_PyTime_ObjectToTimespec(PyTuple_GET_ITEM(times, 0),
inline
            
_PyTime_ObjectToTimespec will not be inlined into os_utime_impl because its definition is unavailable 
os_utime_impl
gvn
                                     
load of type %struct._object* not eliminated because it is clobbered by call 
os_utime_impl
gvn
                                     
load of type %struct._object* not eliminated because it is clobbered by call 
os_utime
4589
                                     &a_sec, &a_nsec, _PyTime_ROUND_FLOOR) == -1 ||
4590
            _PyTime_ObjectToTimespec(PyTuple_GET_ITEM(times, 1),
inline
            
_PyTime_ObjectToTimespec will not be inlined into os_utime_impl because its definition is unavailable 
os_utime_impl
gvn
                                     
load of type %struct._object* not eliminated because it is clobbered by call 
os_utime_impl
gvn
                                     
load of type %struct._object* not eliminated because it is clobbered by call 
os_utime
4591
                                     &m_sec, &m_nsec, _PyTime_ROUND_FLOOR) == -1) {
4592
            goto exit;
4593
        }
4594
        utime.atime_s = a_sec;
gvn
                        
load of type i64 not eliminated because it is clobbered by call 
os_utime_impl
gvn
                        
load of type i64 not eliminated because it is clobbered by call 
os_utime
4595
        utime.atime_ns = a_nsec;
gvn
                         
load of type i64 not eliminated because it is clobbered by call 
os_utime_impl
gvn
                         
load of type i64 not eliminated because it is clobbered by call 
os_utime
4596
        utime.mtime_s = m_sec;
gvn
                        
load of type i64 not eliminated because it is clobbered by call 
os_utime_impl
gvn
                        
load of type i64 not eliminated because it is clobbered by call 
os_utime
4597
        utime.mtime_ns = m_nsec;
gvn
                         
load of type i64 not eliminated because it is clobbered by call 
os_utime_impl
gvn
                         
load of type i64 not eliminated because it is clobbered by call 
os_utime
4598
    }
4599
    else if (ns) {
4600
        if (!PyTuple_CheckExact(ns) || (PyTuple_Size(ns) != 2)) {
inline
                                        
PyTuple_Size will not be inlined into os_utime_impl because its definition is unavailable 
os_utime_impl
4601
            PyErr_SetString(PyExc_TypeError,
inline
            
PyErr_SetString will not be inlined into os_utime_impl because its definition is unavailable 
os_utime_impl
gvn
                            
load of type %struct._object* not eliminated because it is clobbered by call 
os_utime_impl
gvn
                            
load of type %struct._object* not eliminated because it is clobbered by call 
os_utime
4602
                         "utime: 'ns' must be a tuple of two ints");
4603
            goto exit;
4604
        }
4605
        utime.now = 0;
4606
        if (!split_py_long_to_s_and_ns(PyTuple_GET_ITEM(ns, 0),
inline
             
split_py_long_to_s_and_ns can be inlined into os_utime_impl with cost=235 (threshold=250) 
os_utime_impl
inline
             
split_py_long_to_s_and_ns inlined into os_utime_impl 
os_utime_impl
gvn
                                       
load of type %struct._object* not eliminated because it is clobbered by call 
os_utime_impl
gvn
                                       
load of type %struct._object* not eliminated because it is clobbered by call 
os_utime
4607
                                      &utime.atime_s, &utime.atime_ns) ||
4608
            !split_py_long_to_s_and_ns(PyTuple_GET_ITEM(ns, 1),
inline
             
split_py_long_to_s_and_ns can be inlined into os_utime_impl with cost=-14765 (threshold=250) 
os_utime_impl
inline
             
split_py_long_to_s_and_ns inlined into os_utime_impl 
os_utime_impl
gvn
                                       
load of type %struct._object* not eliminated because it is clobbered by call 
os_utime_impl
gvn
                                       
load of type %struct._object* not eliminated because it is clobbered by call 
os_utime
4609
                                       &utime.mtime_s, &utime.mtime_ns)) {
4610
            goto exit;
4611
        }
4612
    }
4613
    else {
4614
        /* times and ns are both None/unspecified. use "now". */
4615
        utime.now = 1;
4616
    }
4617

4618
#if !defined(UTIME_HAVE_NOFOLLOW_SYMLINKS)
4619
    if (follow_symlinks_specified("utime", follow_symlinks))
4620
        goto exit;
4621
#endif
4622

4623
    if (path_and_dir_fd_invalid("utime", path, dir_fd) ||
inline
        
path_and_dir_fd_invalid can be inlined into os_utime_impl with cost=-14955 (threshold=250) 
os_utime_impl
inline
        
path_and_dir_fd_invalid inlined into os_utime_impl 
os_utime_impl
4624
        dir_fd_and_fd_invalid("utime", dir_fd, path->fd) ||
inline
        
dir_fd_and_fd_invalid can be inlined into os_utime_impl with cost=-14975 (threshold=250) 
os_utime_impl
inline
        
dir_fd_and_fd_invalid inlined into os_utime_impl 
os_utime_impl
gvn
                                                     
load of type i32 not eliminated because it is clobbered by call 
os_utime_impl
gvn
                                                     
load of type i32 not eliminated in favor of store because it is clobbered by call 
os_utime
4625
        fd_and_follow_symlinks_invalid("utime", path->fd, follow_symlinks))
inline
        
fd_and_follow_symlinks_invalid can be inlined into os_utime_impl with cost=25 (threshold=250) 
os_utime_impl
inline
        
fd_and_follow_symlinks_invalid inlined into os_utime_impl 
os_utime_impl
gvn
                                                      
load of type i32 eliminated in favor of load 
os_utime_impl
4626
        goto exit;
4627

4628
#if !defined(HAVE_UTIMENSAT)
4629
    if ((dir_fd != DEFAULT_DIR_FD) && (!follow_symlinks)) {
4630
        PyErr_SetString(PyExc_ValueError,
4631
                     "utime: cannot use dir_fd and follow_symlinks "
4632
                     "together on this platform");
4633
        goto exit;
4634
    }
4635
#endif
4636

4637
#ifdef MS_WINDOWS
4638
    Py_BEGIN_ALLOW_THREADS
4639
    hFile = CreateFileW(path->wide, FILE_WRITE_ATTRIBUTES, 0,
4640
                        NULL, OPEN_EXISTING,
4641
                        FILE_FLAG_BACKUP_SEMANTICS, NULL);
4642
    Py_END_ALLOW_THREADS
4643
    if (hFile == INVALID_HANDLE_VALUE) {
4644
        path_error(path);
4645
        goto exit;
4646
    }
4647

4648
    if (utime.now) {
4649
        GetSystemTimeAsFileTime(&mtime);
4650
        atime = mtime;
4651
    }
4652
    else {
4653
        _Py_time_t_to_FILE_TIME(utime.atime_s, utime.atime_ns, &atime);
4654
        _Py_time_t_to_FILE_TIME(utime.mtime_s, utime.mtime_ns, &mtime);
4655
    }
4656
    if (!SetFileTime(hFile, NULL, &atime, &mtime)) {
4657
        /* Avoid putting the file name into the error here,
4658
           as that may confuse the user into believing that
4659
           something is wrong with the file, when it also
4660
           could be the time stamp that gives a problem. */
4661
        PyErr_SetFromWindowsErr(0);
4662
        goto exit;
4663
    }
4664
#else /* MS_WINDOWS */
4665
    Py_BEGIN_ALLOW_THREADS
inline
    
PyEval_SaveThread will not be inlined into os_utime_impl because its definition is unavailable 
os_utime_impl
4666

4667
#ifdef UTIME_HAVE_NOFOLLOW_SYMLINKS
4668
    if ((!follow_symlinks) && (dir_fd == DEFAULT_DIR_FD))
4669
        result = utime_nofollow_symlinks(&utime, path->narrow);
inline
                 
utime_nofollow_symlinks can be inlined into os_utime_impl with cost=-14955 (threshold=250) 
os_utime_impl
inline
                 
utime_nofollow_symlinks inlined into os_utime_impl 
os_utime_impl
gvn
                                                       
load of type i8* not eliminated because it is clobbered by call 
os_utime_impl
gvn
                                                       
load of type i8* not eliminated because it is clobbered by call 
os_utime
4670
    else
4671
#endif
4672

4673
#if defined(HAVE_FUTIMESAT) || defined(HAVE_UTIMENSAT)
4674
    if ((dir_fd != DEFAULT_DIR_FD) || (!follow_symlinks))
4675
        result = utime_dir_fd(&utime, dir_fd, path->narrow, follow_symlinks);
inline
                 
utime_dir_fd can be inlined into os_utime_impl with cost=-14955 (threshold=250) 
os_utime_impl
inline
                 
utime_dir_fd inlined into os_utime_impl 
os_utime_impl
gvn
                                                    
load of type i8* not eliminated because it is clobbered by call 
os_utime_impl
gvn
                                                    
load of type i8* not eliminated because it is clobbered by call 
os_utime
4676
    else
4677
#endif
4678

4679
#if defined(HAVE_FUTIMES) || defined(HAVE_FUTIMENS)
4680
    if (path->fd != -1)
gvn
              
load of type i32 not eliminated in favor of load because it is clobbered by call 
os_utime_impl
gvn
              
load of type i32 not eliminated because it is clobbered by call 
os_utime
4681
        result = utime_fd(&utime, path->fd);
inline
                 
utime_fd can be inlined into os_utime_impl with cost=-14965 (threshold=250) 
os_utime_impl
inline
                 
utime_fd inlined into os_utime_impl 
os_utime_impl
4682
    else
4683
#endif
4684

4685
    result = utime_default(&utime, path->narrow);
inline
             
utime_default can be inlined into os_utime_impl with cost=-14955 (threshold=250) 
os_utime_impl
inline
             
utime_default inlined into os_utime_impl 
os_utime_impl
gvn
                                         
load of type i8* not eliminated because it is clobbered by call 
os_utime_impl
gvn
                                         
load of type i8* not eliminated because it is clobbered by call 
os_utime
4686

4687
    Py_END_ALLOW_THREADS
inline
    
PyEval_RestoreThread will not be inlined into os_utime_impl because its definition is unavailable 
os_utime_impl
4688

4689
    if (result < 0) {
4690
        /* see previous comment about not putting filename in error here */
4691
        return_value = posix_error();
inline
                       
posix_error can be inlined into os_utime_impl with cost=10 (threshold=375) 
os_utime_impl
inline
                       
posix_error inlined into os_utime_impl 
os_utime_impl
4692
        goto exit;
4693
    }
4694

4695
#endif /* MS_WINDOWS */
4696

4697
    Py_INCREF(Py_None);
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_utime_impl
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_utime
4698
    return_value = Py_None;
4699

4700
exit:
4701
#ifdef MS_WINDOWS
4702
    if (hFile != INVALID_HANDLE_VALUE)
4703
        CloseHandle(hFile);
4704
#endif
4705
    return return_value;
4706
}
4707

4708
/* Process operations */
4709

4710

4711
/*[clinic input]
4712
os._exit
4713

4714
    status: int
4715

4716
Exit to the system with specified status, without normal exit processing.
4717
[clinic start generated code]*/
4718

4719
static PyObject *
4720
os__exit_impl(PyObject *module, int status)
4721
/*[clinic end generated code: output=116e52d9c2260d54 input=5e6d57556b0c4a62]*/
4722
{
4723
    _exit(status);
inline
    
_exit will not be inlined into os__exit_impl because its definition is unavailable 
os__exit_impl
4724
    return NULL; /* Make gcc -Wall happy */
4725
}
4726

4727
#if defined(HAVE_WEXECV) || defined(HAVE_WSPAWNV)
4728
#define EXECV_CHAR wchar_t
4729
#else
4730
#define EXECV_CHAR char
4731
#endif
4732

4733
#if defined(HAVE_EXECV) || defined(HAVE_SPAWNV)
4734
static void
4735
free_string_array(EXECV_CHAR **array, Py_ssize_t count)
4736
{
4737
    Py_ssize_t i;
4738
    for (i = 0; i < count; i++)
loop-vectorize
    
loop not vectorized 
os_execv
loop-vectorize
    
loop not vectorized 
os_execve
loop-vectorize
    
loop not vectorized 
parse_arglist
4739
        PyMem_Free(array[i]);
inline
        
PyMem_Free will not be inlined into free_string_array because its definition is unavailable 
free_string_array
gvn
                   
load of type i8* not eliminated because it is clobbered by call 
parse_arglist
gvn
                   
load of type i8* not eliminated because it is clobbered by call 
os_execv_impl
gvn
                   
load of type i8* not eliminated because it is clobbered by call 
os_execv
gvn
                   
load of type i8* not eliminated because it is clobbered by call 
parse_envlist
gvn
                   
load of type i8* not eliminated because it is clobbered by call 
os_execve_impl
gvn
                   
load of type i8* not eliminated because it is clobbered by call 
os_execve
loop-vectorize
        
loop not vectorized: call instruction cannot be vectorized 
os_execv
loop-vectorize
        
loop not vectorized: call instruction cannot be vectorized 
os_execve
loop-vectorize
        
loop not vectorized: call instruction cannot be vectorized 
parse_arglist
4740
    PyMem_DEL(array);
inline
    
PyMem_Free will not be inlined into free_string_array because its definition is unavailable 
free_string_array
4741
}
4742

4743
static int
4744
fsconvert_strdup(PyObject *o, EXECV_CHAR **out)
4745
{
4746
    Py_ssize_t size;
4747
    PyObject *ub;
licm
    
hosting bitcast 
parse_arglist
licm
    
hosting bitcast 
parse_envlist
4748
    int result = 0;
4749
#if defined(HAVE_WEXECV) || defined(HAVE_WSPAWNV)
4750
    if (!PyUnicode_FSDecoder(o, &ub))
4751
        return 0;
4752
    *out = PyUnicode_AsWideCharString(ub, &size);
4753
    if (*out)
4754
        result = 1;
4755
#else
4756
    if (!PyUnicode_FSConverter(o, &ub))
inline
         
PyUnicode_FSConverter will not be inlined into fsconvert_strdup because its definition is unavailable 
fsconvert_strdup
4757
        return 0;
4758
    size = PyBytes_GET_SIZE(ub);
gvn
           
load of type %struct.PyVarObject* not eliminated because it is clobbered by call 
fsconvert_strdup
licm
           
hosting bitcast 
parse_arglist
licm
           
failed to move load with loop-invariant address because the loop may invalidate its value 
parse_arglist
gvn
           
load of type %struct.PyVarObject* not eliminated because it is clobbered by call 
parse_arglist
licm
           
hosting bitcast 
parse_envlist
licm
           
failed to move load with loop-invariant address because the loop may invalidate its value 
parse_envlist
gvn
           
load of type %struct.PyVarObject* not eliminated because it is clobbered by call 
parse_envlist
licm
           
failed to move load with loop-invariant address because the loop may invalidate its value 
os_execve_impl
gvn
           
load of type %struct.PyVarObject* not eliminated because it is clobbered by call 
os_execve_impl
licm
           
failed to move load with loop-invariant address because the loop may invalidate its value 
os_execve
gvn
           
load of type %struct.PyVarObject* not eliminated because it is clobbered by call 
os_execve
4759
    *out = PyMem_Malloc(size + 1);
inline
           
PyMem_Malloc will not be inlined into fsconvert_strdup because its definition is unavailable 
fsconvert_strdup
4760
    if (*out) {
4761
        memcpy(*out, PyBytes_AS_STRING(ub), size + 1);
gvn
                     
load of type %struct.PyBytesObject* not eliminated because it is clobbered by call 
fsconvert_strdup
licm
                     
hosting bitcast 
parse_arglist
licm
                     
failed to move load with loop-invariant address because the loop may invalidate its value 
parse_arglist
gvn
                     
load of type %struct.PyBytesObject* not eliminated because it is clobbered by store 
parse_arglist
licm
                     
hosting bitcast 
parse_envlist
licm
                     
failed to move load with loop-invariant address because the loop may invalidate its value 
parse_envlist
gvn
                     
load of type %struct.PyBytesObject* not eliminated because it is clobbered by store 
parse_envlist
licm
                     
failed to move load with loop-invariant address because the loop may invalidate its value 
os_execve_impl
gvn
                     
load of type %struct.PyBytesObject* not eliminated because it is clobbered by store 
os_execve_impl
licm
                     
failed to move load with loop-invariant address because the loop may invalidate its value 
os_execve
gvn
                     
load of type %struct.PyBytesObject* not eliminated because it is clobbered by store 
os_execve
4762
        result = 1;
4763
    } else
4764
        PyErr_NoMemory();
inline
        
PyErr_NoMemory will not be inlined into fsconvert_strdup because its definition is unavailable 
fsconvert_strdup
4765
#endif
4766
    Py_DECREF(ub);
gvn
    
load of type %struct._object* not eliminated because it is clobbered by call 
fsconvert_strdup
licm
    
failed to move load with loop-invariant address because the loop may invalidate its value 
parse_arglist
gvn
    
load of type %struct._object* not eliminated because it is clobbered by call 
parse_arglist
licm
    
failed to move load with loop-invariant address because the loop may invalidate its value 
parse_envlist
gvn
    
load of type %struct._object* not eliminated because it is clobbered by call 
parse_envlist
licm
    
failed to move load with loop-invariant address because the loop may invalidate its value 
os_execve_impl
gvn
    
load of type %struct._object* not eliminated because it is clobbered by call 
os_execve_impl
licm
    
failed to move load with loop-invariant address because the loop may invalidate its value 
os_execve
gvn
    
load of type %struct._object* not eliminated because it is clobbered by call 
os_execve
4767
    return result;
4768
}
4769
#endif
4770

4771
#if defined(HAVE_EXECV) || defined (HAVE_FEXECVE)
4772
static EXECV_CHAR**
4773
parse_envlist(PyObject* env, Py_ssize_t *envc_ptr)
4774
{
4775
    Py_ssize_t i, pos, envc;
4776
    PyObject *keys=NULL, *vals=NULL;
4777
    PyObject *key, *val, *key2, *val2, *keyval;
4778
    EXECV_CHAR **envlist;
4779

4780
    i = PyMapping_Size(env);
inline
        
PyMapping_Size will not be inlined into parse_envlist because its definition is unavailable 
parse_envlist
4781
    if (i < 0)
4782
        return NULL;
4783
    envlist = PyMem_NEW(EXECV_CHAR *, i + 1);
inline
              
PyMem_Malloc will not be inlined into parse_envlist because its definition is unavailable 
parse_envlist
4784
    if (envlist == NULL) {
4785
        PyErr_NoMemory();
inline
        
PyErr_NoMemory will not be inlined into parse_envlist because its definition is unavailable 
parse_envlist
4786
        return NULL;
4787
    }
4788
    envc = 0;
4789
    keys = PyMapping_Keys(env);
inline
           
PyMapping_Keys will not be inlined into parse_envlist because its definition is unavailable 
parse_envlist
4790
    if (!keys)
4791
        goto error;
4792
    vals = PyMapping_Values(env);
inline
           
PyMapping_Values will not be inlined into parse_envlist because its definition is unavailable 
parse_envlist
4793
    if (!vals)
4794
        goto error;
4795
    if (!PyList_Check(keys) || !PyList_Check(vals)) {
gvn
         
load of type %struct._typeobject* not eliminated because it is clobbered by call 
parse_envlist
gvn
                                
load of type %struct._typeobject* not eliminated because it is clobbered by call 
parse_envlist
gvn
         
load of type %struct._typeobject* not eliminated because it is clobbered by call 
os_execve_impl
gvn
                                
load of type %struct._typeobject* not eliminated because it is clobbered by call 
os_execve_impl
gvn
         
load of type %struct._typeobject* not eliminated because it is clobbered by call 
os_execve
gvn
                                
load of type %struct._typeobject* not eliminated because it is clobbered by call 
os_execve
4796
        PyErr_Format(PyExc_TypeError,
inline
        
PyErr_Format will not be inlined into parse_envlist because its definition is unavailable 
parse_envlist
gvn
                     
load of type %struct._object* not eliminated because it is clobbered by call 
parse_envlist
gvn
                     
load of type %struct._object* not eliminated because it is clobbered by call 
os_execve_impl
gvn
                     
load of type %struct._object* not eliminated because it is clobbered by call 
os_execve
4797
                     "env.keys() or env.values() is not a list");
4798
        goto error;
4799
    }
4800

4801
    for (pos = 0; pos < i; pos++) {
loop-vectorize
    
loop not vectorized: loop control flow is not understood by vectorizer 
os_execve
loop-vectorize
    
loop not vectorized 
os_execve
4802
        key = PyList_GetItem(keys, pos);
inline
              
PyList_GetItem will not be inlined into parse_envlist because its definition is unavailable 
parse_envlist
4803
        val = PyList_GetItem(vals, pos);
inline
              
PyList_GetItem will not be inlined into parse_envlist because its definition is unavailable 
parse_envlist
4804
        if (!key || !val)
4805
            goto error;
4806

4807
#if defined(HAVE_WEXECV) || defined(HAVE_WSPAWNV)
4808
        if (!PyUnicode_FSDecoder(key, &key2))
4809
            goto error;
4810
        if (!PyUnicode_FSDecoder(val, &val2)) {
4811
            Py_DECREF(key2);
4812
            goto error;
4813
        }
4814
        keyval = PyUnicode_FromFormat("%U=%U", key2, val2);
4815
#else
4816
        if (!PyUnicode_FSConverter(key, &key2))
inline
             
PyUnicode_FSConverter will not be inlined into parse_envlist because its definition is unavailable 
parse_envlist
4817
            goto error;
4818
        if (!PyUnicode_FSConverter(val, &val2)) {
inline
             
PyUnicode_FSConverter will not be inlined into parse_envlist because its definition is unavailable 
parse_envlist
4819
            Py_DECREF(key2);
gvn
            
load of type i64 not eliminated because it is clobbered by call 
parse_envlist
gvn
            
load of type i64 not eliminated because it is clobbered by call 
os_execve_impl
gvn
            
load of type i64 not eliminated because it is clobbered by call 
os_execve
4820
            goto error;
4821
        }
4822
        keyval = PyBytes_FromFormat("%s=%s", PyBytes_AS_STRING(key2),
inline
                 
PyBytes_FromFormat will not be inlined into parse_envlist because its definition is unavailable 
parse_envlist
licm
                                             
failed to move load with loop-invariant address because the loop may invalidate its value 
parse_envlist
gvn
                                             
load of type %struct._object* not eliminated because it is clobbered by call 
parse_envlist
licm
                                             
failed to move load with loop-invariant address because the loop may invalidate its value 
os_execve_impl
gvn
                                             
load of type %struct._object* not eliminated because it is clobbered by call 
os_execve_impl
licm
                                             
failed to move load with loop-invariant address because the loop may invalidate its value 
os_execve
gvn
                                             
load of type %struct._object* not eliminated because it is clobbered by call 
os_execve
4823
                                             PyBytes_AS_STRING(val2));
licm
                                             
hosting bitcast 
parse_envlist
licm
                                             
failed to move load with loop-invariant address because the loop may invalidate its value 
parse_envlist
gvn
                                             
load of type %struct.PyBytesObject* not eliminated because it is clobbered by call 
parse_envlist
licm
                                             
failed to move load with loop-invariant address because the loop may invalidate its value 
os_execve_impl
gvn
                                             
load of type %struct.PyBytesObject* not eliminated because it is clobbered by call 
os_execve_impl
licm
                                             
failed to move load with loop-invariant address because the loop may invalidate its value 
os_execve
gvn
                                             
load of type %struct.PyBytesObject* not eliminated because it is clobbered by call 
os_execve
4824
#endif
4825
        Py_DECREF(key2);
licm
        
failed to move load with loop-invariant address because the loop may invalidate its value 
parse_envlist
gvn
        
load of type %struct._object* not eliminated in favor of load because it is clobbered by call 
parse_envlist
licm
        
failed to move load with loop-invariant address because the loop may invalidate its value 
os_execve_impl
gvn
        
load of type %struct._object* not eliminated in favor of load because it is clobbered by call 
os_execve_impl
licm
        
failed to move load with loop-invariant address because the loop may invalidate its value 
os_execve
gvn
        
load of type %struct._object* not eliminated in favor of load because it is clobbered by call 
os_execve
4826
        Py_DECREF(val2);
licm
        
failed to move load with loop-invariant address because the loop may invalidate its value 
parse_envlist
gvn
        
load of type %struct._object* not eliminated because it is clobbered by call 
parse_envlist
licm
        
failed to move load with loop-invariant address because the loop may invalidate its value 
os_execve_impl
gvn
        
load of type %struct._object* not eliminated because it is clobbered by call 
os_execve_impl
licm
        
failed to move load with loop-invariant address because the loop may invalidate its value 
os_execve
gvn
        
load of type %struct._object* not eliminated because it is clobbered by call 
os_execve
4827
        if (!keyval)
4828
            goto error;
4829

4830
        if (!fsconvert_strdup(keyval, &envlist[envc++])) {
inline
             
fsconvert_strdup can be inlined into parse_envlist with cost=-14830 (threshold=250) 
parse_envlist
inline
             
fsconvert_strdup inlined into parse_envlist 
parse_envlist
4831
            Py_DECREF(keyval);
gvn
            
load of type %struct._typeobject* not eliminated because it is clobbered by call 
parse_envlist
gvn
            
load of type %struct._typeobject* not eliminated because it is clobbered by call 
os_execve_impl
gvn
            
load of type %struct._typeobject* not eliminated because it is clobbered by call 
os_execve
4832
            goto error;
4833
        }
4834

4835
        Py_DECREF(keyval);
gvn
        
load of type i64 not eliminated because it is clobbered by call 
parse_envlist
gvn
        
load of type i64 not eliminated because it is clobbered by call 
os_execve_impl
gvn
        
load of type i64 not eliminated because it is clobbered by call 
os_execve
4836
    }
4837
    Py_DECREF(vals);
gvn
    
load of type i64 not eliminated because it is clobbered by call 
parse_envlist
gvn
    
load of type i64 not eliminated because it is clobbered by store 
os_execve_impl
gvn
    
load of type i64 not eliminated because it is clobbered by store 
os_execve
4838
    Py_DECREF(keys);
gvn
    
load of type i64 not eliminated because it is clobbered by store 
parse_envlist
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_execve_impl
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_execve
4839

4840
    envlist[envc] = 0;
4841
    *envc_ptr = envc;
4842
    return envlist;
4843

4844
error:
4845
    Py_XDECREF(keys);
gvn
    
load of type i64 not eliminated because it is clobbered by call 
parse_envlist
gvn
    
load of type i64 not eliminated because it is clobbered by store 
os_execve_impl
gvn
    
load of type i64 not eliminated because it is clobbered by store 
os_execve
4846
    Py_XDECREF(vals);
gvn
    
load of type i64 not eliminated because it is clobbered by call 
parse_envlist
gvn
    
load of type i64 not eliminated because it is clobbered by store 
os_execve_impl
gvn
    
load of type i64 not eliminated because it is clobbered by store 
os_execve
4847
    free_string_array(envlist, envc);
inline
    
free_string_array can be inlined into parse_envlist with cost=65 (threshold=250) 
parse_envlist
inline
    
free_string_array inlined into parse_envlist 
parse_envlist
4848
    return NULL;
4849
}
4850

4851
static EXECV_CHAR**
4852
parse_arglist(PyObject* argv, Py_ssize_t *argc)
4853
{
4854
    int i;
4855
    EXECV_CHAR **argvlist = PyMem_NEW(EXECV_CHAR *, *argc+1);
inline
                            
PyMem_Malloc will not be inlined into parse_arglist because its definition is unavailable 
parse_arglist
4856
    if (argvlist == NULL) {
4857
        PyErr_NoMemory();
inline
        
PyErr_NoMemory will not be inlined into parse_arglist because its definition is unavailable 
parse_arglist
4858
        return NULL;
4859
    }
4860
    for (i = 0; i < *argc; i++) {
licm
                    
failed to move load with loop-invariant address because the loop may invalidate its value 
parse_arglist
gvn
                    
load of type i64 not eliminated in favor of load because it is clobbered by call 
parse_arglist
loop-vectorize
    
loop not vectorized: loop control flow is not understood by vectorizer 
parse_arglist
loop-vectorize
    
loop not vectorized 
parse_arglist
4861
        PyObject* item = PySequence_ITEM(argv, i);
licm
                         
hosting getelementptr 
parse_arglist
licm
                         
failed to move load with loop-invariant address because the loop may invalidate its value 
parse_arglist
gvn
                         
load of type %struct._typeobject* not eliminated because it is clobbered by call 
parse_arglist
4862
        if (item == NULL)
4863
            goto fail;
4864
        if (!fsconvert_strdup(item, &argvlist[i])) {
inline
             
fsconvert_strdup can be inlined into parse_arglist with cost=170 (threshold=250) 
parse_arglist
inline
             
fsconvert_strdup inlined into parse_arglist 
parse_arglist
4865
            Py_DECREF(item);
gvn
            
load of type %struct._typeobject* not eliminated because it is clobbered by call 
parse_arglist
4866
            goto fail;
4867
        }
4868
        Py_DECREF(item);
gvn
        
load of type i64 not eliminated because it is clobbered by call 
parse_arglist
4869
    }
4870
    argvlist[*argc] = NULL;
4871
    return argvlist;
4872
fail:
4873
    *argc = i;
4874
    free_string_array(argvlist, *argc);
inline
    
free_string_array can be inlined into parse_arglist with cost=65 (threshold=250) 
parse_arglist
inline
    
free_string_array inlined into parse_arglist 
parse_arglist
4875
    return NULL;
4876
}
4877

4878
#endif
4879

4880

4881
#ifdef HAVE_EXECV
4882
/*[clinic input]
4883
os.execv
4884

4885
    path: path_t
4886
        Path of executable file.
4887
    argv: object
4888
        Tuple or list of strings.
4889
    /
4890

4891
Execute an executable path with arguments, replacing current process.
4892
[clinic start generated code]*/
4893

4894
static PyObject *
4895
os_execv_impl(PyObject *module, path_t *path, PyObject *argv)
4896
/*[clinic end generated code: output=3b52fec34cd0dafd input=9bac31efae07dac7]*/
4897
{
4898
    EXECV_CHAR **argvlist;
4899
    Py_ssize_t argc;
4900

4901
    /* execv has two arguments: (path, argv), where
4902
       argv is a list or tuple of strings. */
4903

4904
    if (!PyList_Check(argv) && !PyTuple_Check(argv)) {
4905
        PyErr_SetString(PyExc_TypeError,
inline
        
PyErr_SetString will not be inlined into os_execv_impl because its definition is unavailable 
os_execv_impl
gvn
                        
load of type %struct._object* not eliminated because it is clobbered by call 
os_execv
4906
                        "execv() arg 2 must be a tuple or list");
4907
        return NULL;
4908
    }
4909
    argc = PySequence_Size(argv);
inline
           
PySequence_Size will not be inlined into os_execv_impl because its definition is unavailable 
os_execv_impl
4910
    if (argc < 1) {
4911
        PyErr_SetString(PyExc_ValueError, "execv() arg 2 must not be empty");
inline
        
PyErr_SetString will not be inlined into os_execv_impl because its definition is unavailable 
os_execv_impl
gvn
                        
load of type %struct._object* not eliminated because it is clobbered by call 
os_execv_impl
gvn
                        
load of type %struct._object* not eliminated because it is clobbered by call 
os_execv
4912
        return NULL;
4913
    }
4914

4915
    argvlist = parse_arglist(argv, &argc);
inline
               
parse_arglist too costly to inline (cost=535, threshold=250) 
os_execv_impl
inline
               
parse_arglist will not be inlined into os_execv_impl 
os_execv_impl
inline
               
parse_arglist too costly to inline (cost=535, threshold=250) 
os_execv
inline
               
parse_arglist will not be inlined into os_execv 
os_execv
4916
    if (argvlist == NULL) {
4917
        return NULL;
4918
    }
4919
    if (!argvlist[0][0]) {
gvn
         
load of type i8* not eliminated because it is clobbered by call 
os_execv_impl
gvn
         
load of type i8* not eliminated because it is clobbered by call 
os_execv
4920
        PyErr_SetString(PyExc_ValueError,
inline
        
PyErr_SetString will not be inlined into os_execv_impl because its definition is unavailable 
os_execv_impl
gvn
                        
load of type %struct._object* not eliminated because it is clobbered by call 
os_execv_impl
gvn
                        
load of type %struct._object* not eliminated because it is clobbered by call 
os_execv
4921
            "execv() arg 2 first element cannot be empty");
4922
        free_string_array(argvlist, argc);
inline
        
free_string_array can be inlined into os_execv_impl with cost=65 (threshold=250) 
os_execv_impl
inline
        
free_string_array inlined into os_execv_impl 
os_execv_impl
gvn
                                    
load of type i64 not eliminated in favor of store because it is clobbered by call 
os_execv_impl
gvn
                                    
load of type i64 not eliminated in favor of store because it is clobbered by call 
os_execv
4923
        return NULL;
4924
    }
4925

4926
    _Py_BEGIN_SUPPRESS_IPH
4927
#ifdef HAVE_WEXECV
4928
    _wexecv(path->wide, argvlist);
4929
#else
4930
    execv(path->narrow, argvlist);
inline
    
execv will not be inlined into os_execv_impl because its definition is unavailable 
os_execv_impl
gvn
                
load of type i8* not eliminated because it is clobbered by call 
os_execv_impl
gvn
                
load of type i8* not eliminated because it is clobbered by call 
os_execv
4931
#endif
4932
    _Py_END_SUPPRESS_IPH
4933

4934
    /* If we get here it's definitely an error */
4935

4936
    free_string_array(argvlist, argc);
inline
    
free_string_array can be inlined into os_execv_impl with cost=65 (threshold=250) 
os_execv_impl
inline
    
free_string_array inlined into os_execv_impl 
os_execv_impl
gvn
                                
load of type i64 not eliminated in favor of store because it is clobbered by call 
os_execv_impl
gvn
                                
load of type i64 not eliminated in favor of store because it is clobbered by call 
os_execv
4937
    return posix_error();
inline
           
posix_error can be inlined into os_execv_impl with cost=10 (threshold=375) 
os_execv_impl
inline
           
posix_error inlined into os_execv_impl 
os_execv_impl
4938
}
4939

4940

4941
/*[clinic input]
4942
os.execve
4943

4944
    path: path_t(allow_fd='PATH_HAVE_FEXECVE')
4945
        Path of executable file.
4946
    argv: object
4947
        Tuple or list of strings.
4948
    env: object
4949
        Dictionary of strings mapping to strings.
4950

4951
Execute an executable path with arguments, replacing current process.
4952
[clinic start generated code]*/
4953

4954
static PyObject *
4955
os_execve_impl(PyObject *module, path_t *path, PyObject *argv, PyObject *env)
4956
/*[clinic end generated code: output=ff9fa8e4da8bde58 input=626804fa092606d9]*/
4957
{
4958
    EXECV_CHAR **argvlist = NULL;
4959
    EXECV_CHAR **envlist;
4960
    Py_ssize_t argc, envc;
4961

4962
    /* execve has three arguments: (path, argv, env), where
4963
       argv is a list or tuple of strings and env is a dictionary
4964
       like posix.environ. */
4965

4966
    if (!PyList_Check(argv) && !PyTuple_Check(argv)) {
4967
        PyErr_SetString(PyExc_TypeError,
inline
        
PyErr_SetString will not be inlined into os_execve_impl because its definition is unavailable 
os_execve_impl
gvn
                        
load of type %struct._object* not eliminated because it is clobbered by call 
os_execve
4968
                        "execve: argv must be a tuple or list");
4969
        goto fail;
4970
    }
4971
    argc = PySequence_Size(argv);
inline
           
PySequence_Size will not be inlined into os_execve_impl because its definition is unavailable 
os_execve_impl
4972
    if (argc < 1) {
4973
        PyErr_SetString(PyExc_ValueError, "execve: argv must not be empty");
inline
        
PyErr_SetString will not be inlined into os_execve_impl because its definition is unavailable 
os_execve_impl
gvn
                        
load of type %struct._object* not eliminated because it is clobbered by call 
os_execve_impl
gvn
                        
load of type %struct._object* not eliminated because it is clobbered by call 
os_execve
4974
        return NULL;
4975
    }
4976

4977
    if (!PyMapping_Check(env)) {
inline
         
PyMapping_Check will not be inlined into os_execve_impl because its definition is unavailable 
os_execve_impl
4978
        PyErr_SetString(PyExc_TypeError,
inline
        
PyErr_SetString will not be inlined into os_execve_impl because its definition is unavailable 
os_execve_impl
gvn
                        
load of type %struct._object* not eliminated because it is clobbered by call 
os_execve_impl
gvn
                        
load of type %struct._object* not eliminated because it is clobbered by call 
os_execve
4979
                        "execve: environment must be a mapping object");
4980
        goto fail;
4981
    }
4982

4983
    argvlist = parse_arglist(argv, &argc);
inline
               
parse_arglist too costly to inline (cost=535, threshold=250) 
os_execve_impl
inline
               
parse_arglist will not be inlined into os_execve_impl 
os_execve_impl
inline
               
parse_arglist too costly to inline (cost=535, threshold=250) 
os_execve
inline
               
parse_arglist will not be inlined into os_execve 
os_execve
4984
    if (argvlist == NULL) {
4985
        goto fail;
4986
    }
4987
    if (!argvlist[0][0]) {
gvn
         
load of type i8* not eliminated because it is clobbered by call 
os_execve_impl
gvn
         
load of type i8* not eliminated because it is clobbered by call 
os_execve
4988
        PyErr_SetString(PyExc_ValueError,
inline
        
PyErr_SetString will not be inlined into os_execve_impl because its definition is unavailable 
os_execve_impl
gvn
                        
load of type %struct._object* not eliminated because it is clobbered by call 
os_execve_impl
gvn
                        
load of type %struct._object* not eliminated because it is clobbered by call 
os_execve
4989
            "execve: argv first element cannot be empty");
4990
        goto fail;
4991
    }
4992

4993
    envlist = parse_envlist(env, &envc);
inline
              
parse_envlist can be inlined into os_execve_impl with cost=-13670 (threshold=250) 
os_execve_impl
inline
              
parse_envlist inlined into os_execve_impl 
os_execve_impl
4994
    if (envlist == NULL)
4995
        goto fail;
4996

4997
    _Py_BEGIN_SUPPRESS_IPH
4998
#ifdef HAVE_FEXECVE
4999
    if (path->fd > -1)
gvn
              
load of type i32 not eliminated because it is clobbered by call 
os_execve_impl
gvn
              
load of type i32 not eliminated in favor of store because it is clobbered by call 
os_execve
5000
        fexecve(path->fd, argvlist, envlist);
inline
        
fexecve will not be inlined into os_execve_impl because its definition is unavailable 
os_execve_impl
5001
    else
5002
#endif
5003
#ifdef HAVE_WEXECV
5004
        _wexecve(path->wide, argvlist, envlist);
5005
#else
5006
        execve(path->narrow, argvlist, envlist);
inline
        
execve will not be inlined into os_execve_impl because its definition is unavailable 
os_execve_impl
gvn
                     
load of type i8* not eliminated because it is clobbered by store 
os_execve_impl
gvn
                     
load of type i8* not eliminated because it is clobbered by store 
os_execve
5007
#endif
5008
    _Py_END_SUPPRESS_IPH
5009

5010
    /* If we get here it's definitely an error */
5011

5012
    path_error(path);
inline
    
path_error can be inlined into os_execve_impl with cost=10 (threshold=375) 
os_execve_impl
inline
    
path_error inlined into os_execve_impl 
os_execve_impl
5013

5014
    free_string_array(envlist, envc);
inline
    
free_string_array can be inlined into os_execve_impl with cost=65 (threshold=250) 
os_execve_impl
inline
    
free_string_array inlined into os_execve_impl 
os_execve_impl
5015
  fail:
5016
    if (argvlist)
5017
        free_string_array(argvlist, argc);
inline
        
free_string_array can be inlined into os_execve_impl with cost=-14935 (threshold=250) 
os_execve_impl
inline
        
free_string_array inlined into os_execve_impl 
os_execve_impl
gvn
                                    
load of type i64 not eliminated in favor of store because it is clobbered by call 
os_execve_impl
gvn
                                    
load of type i64 not eliminated in favor of store because it is clobbered by call 
os_execve
5018
    return NULL;
5019
}
5020

5021
#endif /* HAVE_EXECV */
5022

5023

5024
#if defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV)
5025
/*[clinic input]
5026
os.spawnv
5027

5028
    mode: int
5029
        Mode of process creation.
5030
    path: path_t
5031
        Path of executable file.
5032
    argv: object
5033
        Tuple or list of strings.
5034
    /
5035

5036
Execute the program specified by path in a new process.
5037
[clinic start generated code]*/
5038

5039
static PyObject *
5040
os_spawnv_impl(PyObject *module, int mode, path_t *path, PyObject *argv)
5041
/*[clinic end generated code: output=71cd037a9d96b816 input=43224242303291be]*/
5042
{
5043
    EXECV_CHAR **argvlist;
5044
    int i;
5045
    Py_ssize_t argc;
5046
    intptr_t spawnval;
5047
    PyObject *(*getitem)(PyObject *, Py_ssize_t);
5048

5049
    /* spawnv has three arguments: (mode, path, argv), where
5050
       argv is a list or tuple of strings. */
5051

5052
    if (PyList_Check(argv)) {
5053
        argc = PyList_Size(argv);
5054
        getitem = PyList_GetItem;
5055
    }
5056
    else if (PyTuple_Check(argv)) {
5057
        argc = PyTuple_Size(argv);
5058
        getitem = PyTuple_GetItem;
5059
    }
5060
    else {
5061
        PyErr_SetString(PyExc_TypeError,
5062
                        "spawnv() arg 2 must be a tuple or list");
5063
        return NULL;
5064
    }
5065
    if (argc == 0) {
5066
        PyErr_SetString(PyExc_ValueError,
5067
            "spawnv() arg 2 cannot be empty");
5068
        return NULL;
5069
    }
5070

5071
    argvlist = PyMem_NEW(EXECV_CHAR *, argc+1);
5072
    if (argvlist == NULL) {
5073
        return PyErr_NoMemory();
5074
    }
5075
    for (i = 0; i < argc; i++) {
5076
        if (!fsconvert_strdup((*getitem)(argv, i),
5077
                              &argvlist[i])) {
5078
            free_string_array(argvlist, i);
5079
            PyErr_SetString(
5080
                PyExc_TypeError,
5081
                "spawnv() arg 2 must contain only strings");
5082
            return NULL;
5083
        }
5084
        if (i == 0 && !argvlist[0][0]) {
5085
            free_string_array(argvlist, i);
5086
            PyErr_SetString(
5087
                PyExc_ValueError,
5088
                "spawnv() arg 2 first element cannot be empty");
5089
            return NULL;
5090
        }
5091
    }
5092
    argvlist[argc] = NULL;
5093

5094
    if (mode == _OLD_P_OVERLAY)
5095
        mode = _P_OVERLAY;
5096

5097
    Py_BEGIN_ALLOW_THREADS
5098
    _Py_BEGIN_SUPPRESS_IPH
5099
#ifdef HAVE_WSPAWNV
5100
    spawnval = _wspawnv(mode, path->wide, argvlist);
5101
#else
5102
    spawnval = _spawnv(mode, path->narrow, argvlist);
5103
#endif
5104
    _Py_END_SUPPRESS_IPH
5105
    Py_END_ALLOW_THREADS
5106

5107
    free_string_array(argvlist, argc);
5108

5109
    if (spawnval == -1)
5110
        return posix_error();
5111
    else
5112
        return Py_BuildValue(_Py_PARSE_INTPTR, spawnval);
5113
}
5114

5115

5116
/*[clinic input]
5117
os.spawnve
5118

5119
    mode: int
5120
        Mode of process creation.
5121
    path: path_t
5122
        Path of executable file.
5123
    argv: object
5124
        Tuple or list of strings.
5125
    env: object
5126
        Dictionary of strings mapping to strings.
5127
    /
5128

5129
Execute the program specified by path in a new process.
5130
[clinic start generated code]*/
5131

5132
static PyObject *
5133
os_spawnve_impl(PyObject *module, int mode, path_t *path, PyObject *argv,
5134
                PyObject *env)
5135
/*[clinic end generated code: output=30fe85be56fe37ad input=3e40803ee7c4c586]*/
5136
{
5137
    EXECV_CHAR **argvlist;
5138
    EXECV_CHAR **envlist;
5139
    PyObject *res = NULL;
5140
    Py_ssize_t argc, i, envc;
5141
    intptr_t spawnval;
5142
    PyObject *(*getitem)(PyObject *, Py_ssize_t);
5143
    Py_ssize_t lastarg = 0;
5144

5145
    /* spawnve has four arguments: (mode, path, argv, env), where
5146
       argv is a list or tuple of strings and env is a dictionary
5147
       like posix.environ. */
5148

5149
    if (PyList_Check(argv)) {
5150
        argc = PyList_Size(argv);
5151
        getitem = PyList_GetItem;
5152
    }
5153
    else if (PyTuple_Check(argv)) {
5154
        argc = PyTuple_Size(argv);
5155
        getitem = PyTuple_GetItem;
5156
    }
5157
    else {
5158
        PyErr_SetString(PyExc_TypeError,
5159
                        "spawnve() arg 2 must be a tuple or list");
5160
        goto fail_0;
5161
    }
5162
    if (argc == 0) {
5163
        PyErr_SetString(PyExc_ValueError,
5164
            "spawnve() arg 2 cannot be empty");
5165
        goto fail_0;
5166
    }
5167
    if (!PyMapping_Check(env)) {
5168
        PyErr_SetString(PyExc_TypeError,
5169
                        "spawnve() arg 3 must be a mapping object");
5170
        goto fail_0;
5171
    }
5172

5173
    argvlist = PyMem_NEW(EXECV_CHAR *, argc+1);
5174
    if (argvlist == NULL) {
5175
        PyErr_NoMemory();
5176
        goto fail_0;
5177
    }
5178
    for (i = 0; i < argc; i++) {
5179
        if (!fsconvert_strdup((*getitem)(argv, i),
5180
                              &argvlist[i]))
5181
        {
5182
            lastarg = i;
5183
            goto fail_1;
5184
        }
5185
        if (i == 0 && !argvlist[0][0]) {
5186
            lastarg = i;
5187
            PyErr_SetString(
5188
                PyExc_ValueError,
5189
                "spawnv() arg 2 first element cannot be empty");
5190
            goto fail_1;
5191
        }
5192
    }
5193
    lastarg = argc;
5194
    argvlist[argc] = NULL;
5195

5196
    envlist = parse_envlist(env, &envc);
5197
    if (envlist == NULL)
5198
        goto fail_1;
5199

5200
    if (mode == _OLD_P_OVERLAY)
5201
        mode = _P_OVERLAY;
5202

5203
    Py_BEGIN_ALLOW_THREADS
5204
    _Py_BEGIN_SUPPRESS_IPH
5205
#ifdef HAVE_WSPAWNV
5206
    spawnval = _wspawnve(mode, path->wide, argvlist, envlist);
5207
#else
5208
    spawnval = _spawnve(mode, path->narrow, argvlist, envlist);
5209
#endif
5210
    _Py_END_SUPPRESS_IPH
5211
    Py_END_ALLOW_THREADS
5212

5213
    if (spawnval == -1)
5214
        (void) posix_error();
5215
    else
5216
        res = Py_BuildValue(_Py_PARSE_INTPTR, spawnval);
5217

5218
    while (--envc >= 0)
5219
        PyMem_DEL(envlist[envc]);
5220
    PyMem_DEL(envlist);
5221
  fail_1:
5222
    free_string_array(argvlist, lastarg);
5223
  fail_0:
5224
    return res;
5225
}
5226

5227
#endif /* HAVE_SPAWNV */
5228

5229

5230
#ifdef HAVE_FORK1
5231
/*[clinic input]
5232
os.fork1
5233

5234
Fork a child process with a single multiplexed (i.e., not bound) thread.
5235

5236
Return 0 to child process and PID of child to parent process.
5237
[clinic start generated code]*/
5238

5239
static PyObject *
5240
os_fork1_impl(PyObject *module)
5241
/*[clinic end generated code: output=0de8e67ce2a310bc input=12db02167893926e]*/
5242
{
5243
    pid_t pid;
5244
    int result = 0;
5245
    _PyImport_AcquireLock();
5246
    pid = fork1();
5247
    if (pid == 0) {
5248
        /* child: this clobbers and resets the import lock. */
5249
        PyOS_AfterFork();
5250
    } else {
5251
        /* parent: release the import lock. */
5252
        result = _PyImport_ReleaseLock();
5253
    }
5254
    if (pid == -1)
5255
        return posix_error();
5256
    if (result < 0) {
5257
        /* Don't clobber the OSError if the fork failed. */
5258
        PyErr_SetString(PyExc_RuntimeError,
5259
                        "not holding the import lock");
5260
        return NULL;
5261
    }
5262
    return PyLong_FromPid(pid);
5263
}
5264
#endif /* HAVE_FORK1 */
5265

5266

5267
#ifdef HAVE_FORK
5268
/*[clinic input]
5269
os.fork
5270

5271
Fork a child process.
5272

5273
Return 0 to child process and PID of child to parent process.
5274
[clinic start generated code]*/
5275

5276
static PyObject *
5277
os_fork_impl(PyObject *module)
5278
/*[clinic end generated code: output=3626c81f98985d49 input=13c956413110eeaa]*/
5279
{
5280
    pid_t pid;
5281
    int result = 0;
5282
    _PyImport_AcquireLock();
inline
    
_PyImport_AcquireLock will not be inlined into os_fork_impl because its definition is unavailable 
os_fork_impl
5283
    pid = fork();
inline
          
fork will not be inlined into os_fork_impl because its definition is unavailable 
os_fork_impl
5284
    if (pid == 0) {
5285
        /* child: this clobbers and resets the import lock. */
5286
        PyOS_AfterFork();
inline
        
PyOS_AfterFork will not be inlined into os_fork_impl because its definition is unavailable 
os_fork_impl
5287
    } else {
5288
        /* parent: release the import lock. */
5289
        result = _PyImport_ReleaseLock();
inline
                 
_PyImport_ReleaseLock will not be inlined into os_fork_impl because its definition is unavailable 
os_fork_impl
5290
    }
5291
    if (pid == -1)
5292
        return posix_error();
inline
               
posix_error can be inlined into os_fork_impl with cost=10 (threshold=375) 
os_fork_impl
inline
               
posix_error inlined into os_fork_impl 
os_fork_impl
5293
    if (result < 0) {
5294
        /* Don't clobber the OSError if the fork failed. */
5295
        PyErr_SetString(PyExc_RuntimeError,
inline
        
PyErr_SetString will not be inlined into os_fork_impl because its definition is unavailable 
os_fork_impl
gvn
                        
load of type %struct._object* not eliminated because it is clobbered by call 
os_fork_impl
gvn
                        
load of type %struct._object* not eliminated because it is clobbered by call 
os_fork
5296
                        "not holding the import lock");
5297
        return NULL;
5298
    }
5299
    return PyLong_FromPid(pid);
inline
           
PyLong_FromLong will not be inlined into os_fork_impl because its definition is unavailable 
os_fork_impl
5300
}
5301
#endif /* HAVE_FORK */
5302

5303

5304
#ifdef HAVE_SCHED_H
5305
#ifdef HAVE_SCHED_GET_PRIORITY_MAX
5306
/*[clinic input]
5307
os.sched_get_priority_max
5308

5309
    policy: int
5310

5311
Get the maximum scheduling priority for policy.
5312
[clinic start generated code]*/
5313

5314
static PyObject *
5315
os_sched_get_priority_max_impl(PyObject *module, int policy)
5316
/*[clinic end generated code: output=9e465c6e43130521 input=2097b7998eca6874]*/
5317
{
5318
    int max;
5319

5320
    max = sched_get_priority_max(policy);
inline
          
sched_get_priority_max will not be inlined into os_sched_get_priority_max_impl because its definition is unavailable 
os_sched_get_priority_max_impl
5321
    if (max < 0)
5322
        return posix_error();
inline
               
posix_error can be inlined into os_sched_get_priority_max_impl with cost=10 (threshold=375) 
os_sched_get_priority_max_impl
inline
               
posix_error inlined into os_sched_get_priority_max_impl 
os_sched_get_priority_max_impl
5323
    return PyLong_FromLong(max);
inline
           
PyLong_FromLong will not be inlined into os_sched_get_priority_max_impl because its definition is unavailable 
os_sched_get_priority_max_impl
5324
}
5325

5326

5327
/*[clinic input]
5328
os.sched_get_priority_min
5329

5330
    policy: int
5331

5332
Get the minimum scheduling priority for policy.
5333
[clinic start generated code]*/
5334

5335
static PyObject *
5336
os_sched_get_priority_min_impl(PyObject *module, int policy)
5337
/*[clinic end generated code: output=7595c1138cc47a6d input=21bc8fa0d70983bf]*/
5338
{
5339
    int min = sched_get_priority_min(policy);
inline
              
sched_get_priority_min will not be inlined into os_sched_get_priority_min_impl because its definition is unavailable 
os_sched_get_priority_min_impl
5340
    if (min < 0)
5341
        return posix_error();
inline
               
posix_error can be inlined into os_sched_get_priority_min_impl with cost=10 (threshold=375) 
os_sched_get_priority_min_impl
inline
               
posix_error inlined into os_sched_get_priority_min_impl 
os_sched_get_priority_min_impl
5342
    return PyLong_FromLong(min);
inline
           
PyLong_FromLong will not be inlined into os_sched_get_priority_min_impl because its definition is unavailable 
os_sched_get_priority_min_impl
5343
}
5344
#endif /* HAVE_SCHED_GET_PRIORITY_MAX */
5345

5346

5347
#ifdef HAVE_SCHED_SETSCHEDULER
5348
/*[clinic input]
5349
os.sched_getscheduler
5350
    pid: pid_t
5351
    /
5352

5353
Get the scheduling policy for the process identifiedy by pid.
5354

5355
Passing 0 for pid returns the scheduling policy for the calling process.
5356
[clinic start generated code]*/
5357

5358
static PyObject *
5359
os_sched_getscheduler_impl(PyObject *module, pid_t pid)
5360
/*[clinic end generated code: output=dce4c0bd3f1b34c8 input=5f14cfd1f189e1a0]*/
5361
{
5362
    int policy;
5363

5364
    policy = sched_getscheduler(pid);
inline
             
sched_getscheduler will not be inlined into os_sched_getscheduler_impl because its definition is unavailable 
os_sched_getscheduler_impl
5365
    if (policy < 0)
5366
        return posix_error();
inline
               
posix_error can be inlined into os_sched_getscheduler_impl with cost=10 (threshold=375) 
os_sched_getscheduler_impl
inline
               
posix_error inlined into os_sched_getscheduler_impl 
os_sched_getscheduler_impl
5367
    return PyLong_FromLong(policy);
inline
           
PyLong_FromLong will not be inlined into os_sched_getscheduler_impl because its definition is unavailable 
os_sched_getscheduler_impl
5368
}
5369
#endif /* HAVE_SCHED_SETSCHEDULER */
5370

5371

5372
#if defined(HAVE_SCHED_SETSCHEDULER) || defined(HAVE_SCHED_SETPARAM)
5373
/*[clinic input]
5374
class os.sched_param "PyObject *" "&SchedParamType"
5375

5376
@classmethod
5377
os.sched_param.__new__
5378

5379
    sched_priority: object
5380
        A scheduling parameter.
5381

5382
Current has only one field: sched_priority");
5383
[clinic start generated code]*/
5384

5385
static PyObject *
5386
os_sched_param_impl(PyTypeObject *type, PyObject *sched_priority)
5387
/*[clinic end generated code: output=48f4067d60f48c13 input=73a4c22f7071fc62]*/
5388
{
5389
    PyObject *res;
5390

5391
    res = PyStructSequence_New(type);
inline
          
PyStructSequence_New will not be inlined into os_sched_param_impl because its definition is unavailable 
os_sched_param_impl
5392
    if (!res)
5393
        return NULL;
5394
    Py_INCREF(sched_priority);
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_sched_param_impl
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_sched_param
5395
    PyStructSequence_SET_ITEM(res, 0, sched_priority);
5396
    return res;
5397
}
5398

5399

5400
PyDoc_VAR(os_sched_param__doc__);
5401

5402
static PyStructSequence_Field sched_param_fields[] = {
5403
    {"sched_priority", "the scheduling priority"},
5404
    {0}
5405
};
5406

5407
static PyStructSequence_Desc sched_param_desc = {
5408
    "sched_param", /* name */
5409
    os_sched_param__doc__, /* doc */
5410
    sched_param_fields,
5411
    1
5412
};
5413

5414
static int
5415
convert_sched_param(PyObject *param, struct sched_param *res)
5416
{
5417
    long priority;
5418

5419
    if (Py_TYPE(param) != &SchedParamType) {
5420
        PyErr_SetString(PyExc_TypeError, "must have a sched_param object");
inline
        
PyErr_SetString will not be inlined into convert_sched_param because its definition is unavailable 
convert_sched_param
5421
        return 0;
5422
    }
5423
    priority = PyLong_AsLong(PyStructSequence_GET_ITEM(param, 0));
inline
               
PyLong_AsLong will not be inlined into convert_sched_param because its definition is unavailable 
convert_sched_param
5424
    if (priority == -1 && PyErr_Occurred())
inline
                          
PyErr_Occurred will not be inlined into convert_sched_param because its definition is unavailable 
convert_sched_param
5425
        return 0;
5426
    if (priority > INT_MAX || priority < INT_MIN) {
5427
        PyErr_SetString(PyExc_OverflowError, "sched_priority out of range");
inline
        
PyErr_SetString will not be inlined into convert_sched_param because its definition is unavailable 
convert_sched_param
gvn
                        
load of type %struct._object* not eliminated because it is clobbered by call 
convert_sched_param
5428
        return 0;
5429
    }
5430
    res->sched_priority = Py_SAFE_DOWNCAST(priority, long, int);
5431
    return 1;
5432
}
5433
#endif /* defined(HAVE_SCHED_SETSCHEDULER) || defined(HAVE_SCHED_SETPARAM) */
5434

5435

5436
#ifdef HAVE_SCHED_SETSCHEDULER
5437
/*[clinic input]
5438
os.sched_setscheduler
5439

5440
    pid: pid_t
5441
    policy: int
5442
    param: sched_param
5443
    /
5444

5445
Set the scheduling policy for the process identified by pid.
5446

5447
If pid is 0, the calling process is changed.
5448
param is an instance of sched_param.
5449
[clinic start generated code]*/
5450

5451
static PyObject *
5452
os_sched_setscheduler_impl(PyObject *module, pid_t pid, int policy,
5453
                           struct sched_param *param)
5454
/*[clinic end generated code: output=b0ac0a70d3b1d705 input=c581f9469a5327dd]*/
5455
{
5456
    /*
5457
    ** sched_setscheduler() returns 0 in Linux, but the previous
5458
    ** scheduling policy under Solaris/Illumos, and others.
5459
    ** On error, -1 is returned in all Operating Systems.
5460
    */
5461
    if (sched_setscheduler(pid, policy, param) == -1)
inline
        
sched_setscheduler will not be inlined into os_sched_setscheduler_impl because its definition is unavailable 
os_sched_setscheduler_impl
5462
        return posix_error();
inline
               
posix_error can be inlined into os_sched_setscheduler_impl with cost=10 (threshold=375) 
os_sched_setscheduler_impl
inline
               
posix_error inlined into os_sched_setscheduler_impl 
os_sched_setscheduler_impl
5463
    Py_RETURN_NONE;
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_sched_setscheduler_impl
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_sched_setscheduler
5464
}
5465
#endif  /* HAVE_SCHED_SETSCHEDULER*/
5466

5467

5468
#ifdef HAVE_SCHED_SETPARAM
5469
/*[clinic input]
5470
os.sched_getparam
5471
    pid: pid_t
5472
    /
5473

5474
Returns scheduling parameters for the process identified by pid.
5475

5476
If pid is 0, returns parameters for the calling process.
5477
Return value is an instance of sched_param.
5478
[clinic start generated code]*/
5479

5480
static PyObject *
5481
os_sched_getparam_impl(PyObject *module, pid_t pid)
5482
/*[clinic end generated code: output=b194e8708dcf2db8 input=18a1ef9c2efae296]*/
5483
{
5484
    struct sched_param param;
5485
    PyObject *result;
5486
    PyObject *priority;
5487

5488
    if (sched_getparam(pid, &param))
inline
        
sched_getparam will not be inlined into os_sched_getparam_impl because its definition is unavailable 
os_sched_getparam_impl
5489
        return posix_error();
inline
               
posix_error can be inlined into os_sched_getparam_impl with cost=10 (threshold=375) 
os_sched_getparam_impl
inline
               
posix_error inlined into os_sched_getparam_impl 
os_sched_getparam_impl
5490
    result = PyStructSequence_New(&SchedParamType);
inline
             
PyStructSequence_New will not be inlined into os_sched_getparam_impl because its definition is unavailable 
os_sched_getparam_impl
5491
    if (!result)
5492
        return NULL;
5493
    priority = PyLong_FromLong(param.sched_priority);
inline
               
PyLong_FromLong will not be inlined into os_sched_getparam_impl because its definition is unavailable 
os_sched_getparam_impl
gvn
                                     
load of type i32 not eliminated because it is clobbered by call 
os_sched_getparam_impl
gvn
                                     
load of type i32 not eliminated because it is clobbered by call 
os_sched_getparam
5494
    if (!priority) {
5495
        Py_DECREF(result);
gvn
        
load of type i64 not eliminated because it is clobbered by call 
os_sched_getparam_impl
gvn
        
load of type i64 not eliminated because it is clobbered by call 
os_sched_getparam
5496
        return NULL;
5497
    }
5498
    PyStructSequence_SET_ITEM(result, 0, priority);
5499
    return result;
5500
}
5501

5502

5503
/*[clinic input]
5504
os.sched_setparam
5505
    pid: pid_t
5506
    param: sched_param
5507
    /
5508

5509
Set scheduling parameters for the process identified by pid.
5510

5511
If pid is 0, sets parameters for the calling process.
5512
param should be an instance of sched_param.
5513
[clinic start generated code]*/
5514

5515
static PyObject *
5516
os_sched_setparam_impl(PyObject *module, pid_t pid,
5517
                       struct sched_param *param)
5518
/*[clinic end generated code: output=8af013f78a32b591 input=6b8d6dfcecdc21bd]*/
5519
{
5520
    if (sched_setparam(pid, param))
inline
        
sched_setparam will not be inlined into os_sched_setparam_impl because its definition is unavailable 
os_sched_setparam_impl
5521
        return posix_error();
inline
               
posix_error can be inlined into os_sched_setparam_impl with cost=10 (threshold=375) 
os_sched_setparam_impl
inline
               
posix_error inlined into os_sched_setparam_impl 
os_sched_setparam_impl
5522
    Py_RETURN_NONE;
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_sched_setparam_impl
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_sched_setparam
5523
}
5524
#endif /* HAVE_SCHED_SETPARAM */
5525

5526

5527
#ifdef HAVE_SCHED_RR_GET_INTERVAL
5528
/*[clinic input]
5529
os.sched_rr_get_interval -> double
5530
    pid: pid_t
5531
    /
5532

5533
Return the round-robin quantum for the process identified by pid, in seconds.
5534

5535
Value returned is a float.
5536
[clinic start generated code]*/
5537

5538
static double
5539
os_sched_rr_get_interval_impl(PyObject *module, pid_t pid)
5540
/*[clinic end generated code: output=7e2d935833ab47dc input=2a973da15cca6fae]*/
5541
{
5542
    struct timespec interval;
5543
    if (sched_rr_get_interval(pid, &interval)) {
inline
        
sched_rr_get_interval will not be inlined into os_sched_rr_get_interval_impl because its definition is unavailable 
os_sched_rr_get_interval_impl
5544
        posix_error();
inline
        
posix_error can be inlined into os_sched_rr_get_interval_impl with cost=10 (threshold=375) 
os_sched_rr_get_interval_impl
inline
        
posix_error inlined into os_sched_rr_get_interval_impl 
os_sched_rr_get_interval_impl
5545
        return -1.0;
5546
    }
5547
    return (double)interval.tv_sec + 1e-9*interval.tv_nsec;
gvn
                            
load of type i64 not eliminated because it is clobbered by call 
os_sched_rr_get_interval_impl
gvn
                                                   
load of type i64 not eliminated because it is clobbered by call 
os_sched_rr_get_interval_impl
gvn
                            
load of type i64 not eliminated because it is clobbered by call 
os_sched_rr_get_interval
gvn
                                                   
load of type i64 not eliminated because it is clobbered by call 
os_sched_rr_get_interval
5548
}
5549
#endif /* HAVE_SCHED_RR_GET_INTERVAL */
5550

5551

5552
/*[clinic input]
5553
os.sched_yield
5554

5555
Voluntarily relinquish the CPU.
5556
[clinic start generated code]*/
5557

5558
static PyObject *
5559
os_sched_yield_impl(PyObject *module)
5560
/*[clinic end generated code: output=902323500f222cac input=e54d6f98189391d4]*/
5561
{
5562
    if (sched_yield())
inline
        
sched_yield will not be inlined into os_sched_yield_impl because its definition is unavailable 
os_sched_yield_impl
5563
        return posix_error();
inline
               
posix_error can be inlined into os_sched_yield_impl with cost=10 (threshold=375) 
os_sched_yield_impl
inline
               
posix_error inlined into os_sched_yield_impl 
os_sched_yield_impl
5564
    Py_RETURN_NONE;
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_sched_yield_impl
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_sched_yield
5565
}
5566

5567
#ifdef HAVE_SCHED_SETAFFINITY
5568
/* The minimum number of CPUs allocated in a cpu_set_t */
5569
static const int NCPUS_START = sizeof(unsigned long) * CHAR_BIT;
5570

5571
/*[clinic input]
5572
os.sched_setaffinity
5573
    pid: pid_t
5574
    mask : object
5575
    /
5576

5577
Set the CPU affinity of the process identified by pid to mask.
5578

5579
mask should be an iterable of integers identifying CPUs.
5580
[clinic start generated code]*/
5581

5582
static PyObject *
5583
os_sched_setaffinity_impl(PyObject *module, pid_t pid, PyObject *mask)
5584
/*[clinic end generated code: output=882d7dd9a229335b input=a0791a597c7085ba]*/
5585
{
5586
    int ncpus;
5587
    size_t setsize;
5588
    cpu_set_t *cpu_set = NULL;
5589
    PyObject *iterator = NULL, *item;
5590

5591
    iterator = PyObject_GetIter(mask);
inline
               
PyObject_GetIter will not be inlined into os_sched_setaffinity_impl because its definition is unavailable 
os_sched_setaffinity_impl
5592
    if (iterator == NULL)
5593
        return NULL;
5594

5595
    ncpus = NCPUS_START;
5596
    setsize = CPU_ALLOC_SIZE(ncpus);
5597
    cpu_set = CPU_ALLOC(ncpus);
inline
              
__sched_cpualloc will not be inlined into os_sched_setaffinity_impl because its definition is unavailable 
os_sched_setaffinity_impl
5598
    if (cpu_set == NULL) {
5599
        PyErr_NoMemory();
inline
        
PyErr_NoMemory will not be inlined into os_sched_setaffinity_impl because its definition is unavailable 
os_sched_setaffinity_impl
5600
        goto error;
5601
    }
5602
    CPU_ZERO_S(setsize, cpu_set);
5603

5604
    while ((item = PyIter_Next(iterator))) {
inline
                   
PyIter_Next will not be inlined into os_sched_setaffinity_impl because its definition is unavailable 
os_sched_setaffinity_impl
5605
        long cpu;
5606
        if (!PyLong_Check(item)) {
5607
            PyErr_Format(PyExc_TypeError,
inline
            
PyErr_Format will not be inlined into os_sched_setaffinity_impl because its definition is unavailable 
os_sched_setaffinity_impl
gvn
                         
load of type %struct._object* not eliminated because it is clobbered by call 
os_sched_setaffinity_impl
gvn
                         
load of type %struct._object* not eliminated because it is clobbered by call 
os_sched_setaffinity
5608
                        "expected an iterator of ints, "
5609
                        "but iterator yielded %R",
5610
                        Py_TYPE(item));
5611
            Py_DECREF(item);
gvn
            
load of type i64 not eliminated because it is clobbered by call 
os_sched_setaffinity_impl
gvn
            
load of type i64 not eliminated because it is clobbered by call 
os_sched_setaffinity
5612
            goto error;
5613
        }
5614
        cpu = PyLong_AsLong(item);
inline
              
PyLong_AsLong will not be inlined into os_sched_setaffinity_impl because its definition is unavailable 
os_sched_setaffinity_impl
5615
        Py_DECREF(item);
gvn
        
load of type i64 not eliminated because it is clobbered by call 
os_sched_setaffinity_impl
gvn
        
load of type i64 not eliminated because it is clobbered by call 
os_sched_setaffinity
5616
        if (cpu < 0) {
5617
            if (!PyErr_Occurred())
inline
                 
PyErr_Occurred will not be inlined into os_sched_setaffinity_impl because its definition is unavailable 
os_sched_setaffinity_impl
5618
                PyErr_SetString(PyExc_ValueError, "negative CPU number");
inline
                
PyErr_SetString will not be inlined into os_sched_setaffinity_impl because its definition is unavailable 
os_sched_setaffinity_impl
gvn
                                
load of type %struct._object* not eliminated because it is clobbered by call 
os_sched_setaffinity_impl
gvn
                                
load of type %struct._object* not eliminated because it is clobbered by call 
os_sched_setaffinity
5619
            goto error;
5620
        }
5621
        if (cpu > INT_MAX - 1) {
5622
            PyErr_SetString(PyExc_OverflowError, "CPU number too large");
inline
            
PyErr_SetString will not be inlined into os_sched_setaffinity_impl because its definition is unavailable 
os_sched_setaffinity_impl
gvn
                            
load of type %struct._object* not eliminated because it is clobbered by call 
os_sched_setaffinity_impl
gvn
                            
load of type %struct._object* not eliminated because it is clobbered by call 
os_sched_setaffinity
5623
            goto error;
5624
        }
5625
        if (cpu >= ncpus) {
5626
            /* Grow CPU mask to fit the CPU number */
5627
            int newncpus = ncpus;
5628
            cpu_set_t *newmask;
5629
            size_t newsetsize;
5630
            while (newncpus <= cpu) {
loop-vectorize
            
loop not vectorized: could not determine number of loop iterations 
os_sched_setaffinity
loop-vectorize
            
loop not vectorized 
os_sched_setaffinity
5631
                if (newncpus > INT_MAX / 2)
5632
                    newncpus = cpu + 1;
licm
                                   
hosting add 
os_sched_setaffinity_impl
licm
                               
hosting trunc 
os_sched_setaffinity_impl
5633
                else
5634
                    newncpus = newncpus * 2;
5635
            }
5636
            newmask = CPU_ALLOC(newncpus);
inline
                      
__sched_cpualloc will not be inlined into os_sched_setaffinity_impl because its definition is unavailable 
os_sched_setaffinity_impl
5637
            if (newmask == NULL) {
5638
                PyErr_NoMemory();
inline
                
PyErr_NoMemory will not be inlined into os_sched_setaffinity_impl because its definition is unavailable 
os_sched_setaffinity_impl
5639
                goto error;
5640
            }
5641
            newsetsize = CPU_ALLOC_SIZE(newncpus);
5642
            CPU_ZERO_S(newsetsize, newmask);
5643
            memcpy(newmask, cpu_set, setsize);
5644
            CPU_FREE(cpu_set);
inline
            
__sched_cpufree will not be inlined into os_sched_setaffinity_impl because its definition is unavailable 
os_sched_setaffinity_impl
5645
            setsize = newsetsize;
5646
            cpu_set = newmask;
5647
            ncpus = newncpus;
5648
        }
5649
        CPU_SET_S(cpu, setsize, cpu_set);
5650
    }
5651
    Py_CLEAR(iterator);
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_sched_setaffinity_impl
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_sched_setaffinity
5652

5653
    if (sched_setaffinity(pid, setsize, cpu_set)) {
inline
        
sched_setaffinity will not be inlined into os_sched_setaffinity_impl because its definition is unavailable 
os_sched_setaffinity_impl
5654
        posix_error();
inline
        
posix_error can be inlined into os_sched_setaffinity_impl with cost=10 (threshold=375) 
os_sched_setaffinity_impl
inline
        
posix_error inlined into os_sched_setaffinity_impl 
os_sched_setaffinity_impl
5655
        goto error;
5656
    }
5657
    CPU_FREE(cpu_set);
inline
    
__sched_cpufree will not be inlined into os_sched_setaffinity_impl because its definition is unavailable 
os_sched_setaffinity_impl
5658
    Py_RETURN_NONE;
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_sched_setaffinity_impl
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_sched_setaffinity
5659

5660
error:
5661
    if (cpu_set)
5662
        CPU_FREE(cpu_set);
inline
        
__sched_cpufree will not be inlined into os_sched_setaffinity_impl because its definition is unavailable 
os_sched_setaffinity_impl
5663
    Py_XDECREF(iterator);
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_sched_setaffinity_impl
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_sched_setaffinity
5664
    return NULL;
5665
}
5666

5667

5668
/*[clinic input]
5669
os.sched_getaffinity
5670
    pid: pid_t
5671
    /
5672

5673
Return the affinity of the process identified by pid (or the current process if zero).
5674

5675
The affinity is returned as a set of CPU identifiers.
5676
[clinic start generated code]*/
5677

5678
static PyObject *
5679
os_sched_getaffinity_impl(PyObject *module, pid_t pid)
5680
/*[clinic end generated code: output=f726f2c193c17a4f input=983ce7cb4a565980]*/
5681
{
5682
    int cpu, ncpus, count;
5683
    size_t setsize;
5684
    cpu_set_t *mask = NULL;
5685
    PyObject *res = NULL;
5686

5687
    ncpus = NCPUS_START;
5688
    while (1) {
loop-vectorize
    
loop not vectorized: loop control flow is not understood by vectorizer 
os_sched_getaffinity
loop-vectorize
    
loop not vectorized 
os_sched_getaffinity
5689
        setsize = CPU_ALLOC_SIZE(ncpus);
5690
        mask = CPU_ALLOC(ncpus);
inline
               
__sched_cpualloc will not be inlined into os_sched_getaffinity_impl because its definition is unavailable 
os_sched_getaffinity_impl
5691
        if (mask == NULL)
5692
            return PyErr_NoMemory();
inline
                   
PyErr_NoMemory will not be inlined into os_sched_getaffinity_impl because its definition is unavailable 
os_sched_getaffinity_impl
5693
        if (sched_getaffinity(pid, setsize, mask) == 0)
inline
            
sched_getaffinity will not be inlined into os_sched_getaffinity_impl because its definition is unavailable 
os_sched_getaffinity_impl
5694
            break;
5695
        CPU_FREE(mask);
inline
        
__sched_cpufree will not be inlined into os_sched_getaffinity_impl because its definition is unavailable 
os_sched_getaffinity_impl
5696
        if (errno != EINVAL)
inline
            
__errno_location will not be inlined into os_sched_getaffinity_impl because its definition is unavailable 
os_sched_getaffinity_impl
gvn
            
load of type i32 not eliminated because it is clobbered by call 
os_sched_getaffinity_impl
gvn
            
load of type i32 not eliminated because it is clobbered by call 
os_sched_getaffinity
5697
            return posix_error();
inline
                   
posix_error can be inlined into os_sched_getaffinity_impl with cost=10 (threshold=375) 
os_sched_getaffinity_impl
inline
                   
posix_error inlined into os_sched_getaffinity_impl 
os_sched_getaffinity_impl
5698
        if (ncpus > INT_MAX / 2) {
5699
            PyErr_SetString(PyExc_OverflowError, "could not allocate "
inline
            
PyErr_SetString will not be inlined into os_sched_getaffinity_impl because its definition is unavailable 
os_sched_getaffinity_impl
gvn
                            
load of type %struct._object* not eliminated because it is clobbered by call 
os_sched_getaffinity_impl
gvn
                            
load of type %struct._object* not eliminated because it is clobbered by call 
os_sched_getaffinity
5700
                            "a large enough CPU set");
5701
            return NULL;
5702
        }
5703
        ncpus = ncpus * 2;
5704
    }
5705

5706
    res = PySet_New(NULL);
inline
          
PySet_New will not be inlined into os_sched_getaffinity_impl because its definition is unavailable 
os_sched_getaffinity_impl
5707
    if (res == NULL)
5708
        goto error;
5709
    for (cpu = 0, count = CPU_COUNT_S(setsize, mask); count; cpu++) {
inline
                          
__sched_cpucount will not be inlined into os_sched_getaffinity_impl because its definition is unavailable 
os_sched_getaffinity_impl
5710
        if (CPU_ISSET_S(cpu, setsize, mask)) {
loop-vectorize
            
loop not vectorized: loop control flow is not understood by vectorizer 
os_sched_getaffinity
loop-vectorize
            
loop not vectorized 
os_sched_getaffinity
5711
            PyObject *cpu_num = PyLong_FromLong(cpu);
inline
                                
PyLong_FromLong will not be inlined into os_sched_getaffinity_impl because its definition is unavailable 
os_sched_getaffinity_impl
5712
            --count;
5713
            if (cpu_num == NULL)
5714
                goto error;
5715
            if (PySet_Add(res, cpu_num)) {
inline
                
PySet_Add will not be inlined into os_sched_getaffinity_impl because its definition is unavailable 
os_sched_getaffinity_impl
5716
                Py_DECREF(cpu_num);
gvn
                
load of type i64 not eliminated because it is clobbered by call 
os_sched_getaffinity_impl
gvn
                
load of type i64 not eliminated because it is clobbered by call 
os_sched_getaffinity
5717
                goto error;
5718
            }
5719
            Py_DECREF(cpu_num);
gvn
            
load of type %struct._typeobject* not eliminated because it is clobbered by call 
os_sched_getaffinity_impl
gvn
            
load of type %struct._typeobject* not eliminated because it is clobbered by call 
os_sched_getaffinity
5720
        }
5721
    }
5722
    CPU_FREE(mask);
inline
    
__sched_cpufree will not be inlined into os_sched_getaffinity_impl because its definition is unavailable 
os_sched_getaffinity_impl
5723
    return res;
5724

5725
error:
5726
    if (mask)
5727
        CPU_FREE(mask);
inline
        
__sched_cpufree will not be inlined into os_sched_getaffinity_impl because its definition is unavailable 
os_sched_getaffinity_impl
5728
    Py_XDECREF(res);
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_sched_getaffinity_impl
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_sched_getaffinity
5729
    return NULL;
5730
}
5731

5732
#endif /* HAVE_SCHED_SETAFFINITY */
5733

5734
#endif /* HAVE_SCHED_H */
5735

5736

5737
/* AIX uses /dev/ptc but is otherwise the same as /dev/ptmx */
5738
/* IRIX has both /dev/ptc and /dev/ptmx, use ptmx */
5739
#if defined(HAVE_DEV_PTC) && !defined(HAVE_DEV_PTMX)
5740
#define DEV_PTY_FILE "/dev/ptc"
5741
#define HAVE_DEV_PTMX
5742
#else
5743
#define DEV_PTY_FILE "/dev/ptmx"
5744
#endif
5745

5746
#if defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY) || defined(HAVE_DEV_PTMX)
5747
#ifdef HAVE_PTY_H
5748
#include <pty.h>
5749
#else
5750
#ifdef HAVE_LIBUTIL_H
5751
#include <libutil.h>
5752
#else
5753
#ifdef HAVE_UTIL_H
5754
#include <util.h>
5755
#endif /* HAVE_UTIL_H */
5756
#endif /* HAVE_LIBUTIL_H */
5757
#endif /* HAVE_PTY_H */
5758
#ifdef HAVE_STROPTS_H
5759
#include <stropts.h>
5760
#endif
5761
#endif /* defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY) || defined(HAVE_DEV_PTMX */
5762

5763

5764
#if defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX)
5765
/*[clinic input]
5766
os.openpty
5767

5768
Open a pseudo-terminal.
5769

5770
Return a tuple of (master_fd, slave_fd) containing open file descriptors
5771
for both the master and slave ends.
5772
[clinic start generated code]*/
5773

5774
static PyObject *
5775
os_openpty_impl(PyObject *module)
5776
/*[clinic end generated code: output=98841ce5ec9cef3c input=f3d99fd99e762907]*/
5777
{
5778
    int master_fd = -1, slave_fd = -1;
5779
#ifndef HAVE_OPENPTY
5780
    char * slave_name;
5781
#endif
5782
#if defined(HAVE_DEV_PTMX) && !defined(HAVE_OPENPTY) && !defined(HAVE__GETPTY)
5783
    PyOS_sighandler_t sig_saved;
5784
#ifdef sun
5785
    extern char *ptsname(int fildes);
5786
#endif
5787
#endif
5788

5789
#ifdef HAVE_OPENPTY
5790
    if (openpty(&master_fd, &slave_fd, NULL, NULL, NULL) != 0)
inline
        
openpty will not be inlined into os_openpty_impl because its definition is unavailable 
os_openpty_impl
5791
        goto posix_error;
5792

5793
    if (_Py_set_inheritable(master_fd, 0, NULL) < 0)
inline
        
_Py_set_inheritable will not be inlined into os_openpty_impl because its definition is unavailable 
os_openpty_impl
gvn
                            
load of type i32 not eliminated in favor of store because it is clobbered by call 
os_openpty_impl
gvn
                            
load of type i32 not eliminated in favor of store because it is clobbered by call 
os_openpty
5794
        goto error;
5795
    if (_Py_set_inheritable(slave_fd, 0, NULL) < 0)
inline
        
_Py_set_inheritable will not be inlined into os_openpty_impl because its definition is unavailable 
os_openpty_impl
gvn
                            
load of type i32 not eliminated in favor of store because it is clobbered by call 
os_openpty_impl
gvn
                            
load of type i32 not eliminated in favor of store because it is clobbered by call 
os_openpty
5796
        goto error;
5797

5798
#elif defined(HAVE__GETPTY)
5799
    slave_name = _getpty(&master_fd, O_RDWR, 0666, 0);
5800
    if (slave_name == NULL)
5801
        goto posix_error;
5802
    if (_Py_set_inheritable(master_fd, 0, NULL) < 0)
5803
        goto error;
5804

5805
    slave_fd = _Py_open(slave_name, O_RDWR);
5806
    if (slave_fd < 0)
5807
        goto error;
5808

5809
#else
5810
    master_fd = open(DEV_PTY_FILE, O_RDWR | O_NOCTTY); /* open master */
5811
    if (master_fd < 0)
5812
        goto posix_error;
5813

5814
    sig_saved = PyOS_setsig(SIGCHLD, SIG_DFL);
5815

5816
    /* change permission of slave */
5817
    if (grantpt(master_fd) < 0) {
5818
        PyOS_setsig(SIGCHLD, sig_saved);
5819
        goto posix_error;
5820
    }
5821

5822
    /* unlock slave */
5823
    if (unlockpt(master_fd) < 0) {
5824
        PyOS_setsig(SIGCHLD, sig_saved);
5825
        goto posix_error;
5826
    }
5827

5828
    PyOS_setsig(SIGCHLD, sig_saved);
5829

5830
    slave_name = ptsname(master_fd); /* get name of slave */
5831
    if (slave_name == NULL)
5832
        goto posix_error;
5833

5834
    slave_fd = _Py_open(slave_name, O_RDWR | O_NOCTTY); /* open slave */
5835
    if (slave_fd == -1)
5836
        goto error;
5837

5838
    if (_Py_set_inheritable(master_fd, 0, NULL) < 0)
5839
        goto posix_error;
5840

5841
#if !defined(__CYGWIN__) && !defined(__ANDROID__) && !defined(HAVE_DEV_PTC)
5842
    ioctl(slave_fd, I_PUSH, "ptem"); /* push ptem */
5843
    ioctl(slave_fd, I_PUSH, "ldterm"); /* push ldterm */
5844
#ifndef __hpux
5845
    ioctl(slave_fd, I_PUSH, "ttcompat"); /* push ttcompat */
5846
#endif /* __hpux */
5847
#endif /* HAVE_CYGWIN */
5848
#endif /* HAVE_OPENPTY */
5849

5850
    return Py_BuildValue("(ii)", master_fd, slave_fd);
inline
           
_Py_BuildValue_SizeT will not be inlined into os_openpty_impl because its definition is unavailable 
os_openpty_impl
gvn
                                 
load of type i32 not eliminated because it is clobbered by call 
os_openpty_impl
gvn
                                            
load of type i32 not eliminated because it is clobbered by call 
os_openpty_impl
gvn
                                 
load of type i32 not eliminated because it is clobbered by call 
os_openpty
gvn
                                            
load of type i32 not eliminated because it is clobbered by call 
os_openpty
5851

5852
posix_error:
5853
    posix_error();
inline
    
posix_error can be inlined into os_openpty_impl with cost=10 (threshold=375) 
os_openpty_impl
inline
    
posix_error inlined into os_openpty_impl 
os_openpty_impl
5854
error:
5855
    if (master_fd != -1)
gvn
        
load of type i32 not eliminated in favor of store because it is clobbered by call 
os_openpty_impl
gvn
        
load of type i32 not eliminated in favor of store because it is clobbered by call 
os_openpty
5856
        close(master_fd);
inline
        
close will not be inlined into os_openpty_impl because its definition is unavailable 
os_openpty_impl
5857
    if (slave_fd != -1)
gvn
        
load of type i32 not eliminated in favor of store because it is clobbered by call 
os_openpty_impl
gvn
        
load of type i32 not eliminated in favor of store because it is clobbered by call 
os_openpty
5858
        close(slave_fd);
inline
        
close will not be inlined into os_openpty_impl because its definition is unavailable 
os_openpty_impl
5859
    return NULL;
5860
}
5861
#endif /* defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX) */
5862

5863

5864
#ifdef HAVE_FORKPTY
5865
/*[clinic input]
5866
os.forkpty
5867

5868
Fork a new process with a new pseudo-terminal as controlling tty.
5869

5870
Returns a tuple of (pid, master_fd).
5871
Like fork(), return pid of 0 to the child process,
5872
and pid of child to the parent process.
5873
To both, return fd of newly opened pseudo-terminal.
5874
[clinic start generated code]*/
5875

5876
static PyObject *
5877
os_forkpty_impl(PyObject *module)
5878
/*[clinic end generated code: output=60d0a5c7512e4087 input=f1f7f4bae3966010]*/
5879
{
5880
    int master_fd = -1, result = 0;
5881
    pid_t pid;
5882

5883
    _PyImport_AcquireLock();
inline
    
_PyImport_AcquireLock will not be inlined into os_forkpty_impl because its definition is unavailable 
os_forkpty_impl
5884
    pid = forkpty(&master_fd, NULL, NULL, NULL);
inline
          
forkpty will not be inlined into os_forkpty_impl because its definition is unavailable 
os_forkpty_impl
5885
    if (pid == 0) {
5886
        /* child: this clobbers and resets the import lock. */
5887
        PyOS_AfterFork();
inline
        
PyOS_AfterFork will not be inlined into os_forkpty_impl because its definition is unavailable 
os_forkpty_impl
5888
    } else {
5889
        /* parent: release the import lock. */
5890
        result = _PyImport_ReleaseLock();
inline
                 
_PyImport_ReleaseLock will not be inlined into os_forkpty_impl because its definition is unavailable 
os_forkpty_impl
5891
    }
5892
    if (pid == -1)
5893
        return posix_error();
inline
               
posix_error can be inlined into os_forkpty_impl with cost=10 (threshold=375) 
os_forkpty_impl
inline
               
posix_error inlined into os_forkpty_impl 
os_forkpty_impl
5894
    if (result < 0) {
5895
        /* Don't clobber the OSError if the fork failed. */
5896
        PyErr_SetString(PyExc_RuntimeError,
inline
        
PyErr_SetString will not be inlined into os_forkpty_impl because its definition is unavailable 
os_forkpty_impl
gvn
                        
load of type %struct._object* not eliminated because it is clobbered by call 
os_forkpty_impl
gvn
                        
load of type %struct._object* not eliminated because it is clobbered by call 
os_forkpty
5897
                        "not holding the import lock");
5898
        return NULL;
5899
    }
5900
    return Py_BuildValue("(Ni)", PyLong_FromPid(pid), master_fd);
inline
                                 
PyLong_FromLong will not be inlined into os_forkpty_impl because its definition is unavailable 
os_forkpty_impl
inline
           
_Py_BuildValue_SizeT will not be inlined into os_forkpty_impl because its definition is unavailable 
os_forkpty_impl
gvn
                                                      
load of type i32 not eliminated in favor of store because it is clobbered by call 
os_forkpty_impl
gvn
                                                      
load of type i32 not eliminated in favor of store because it is clobbered by call 
os_forkpty
5901
}
5902
#endif /* HAVE_FORKPTY */
5903

5904

5905
#ifdef HAVE_GETEGID
5906
/*[clinic input]
5907
os.getegid
5908

5909
Return the current process's effective group id.
5910
[clinic start generated code]*/
5911

5912
static PyObject *
5913
os_getegid_impl(PyObject *module)
5914
/*[clinic end generated code: output=67d9be7ac68898a2 input=1596f79ad1107d5d]*/
5915
{
5916
    return _PyLong_FromGid(getegid());
inline
                           
getegid will not be inlined into os_getegid_impl because its definition is unavailable 
os_getegid_impl
inline
           
_PyLong_FromGid can be inlined into os_getegid_impl with cost=45 (threshold=250) 
os_getegid_impl
inline
           
_PyLong_FromGid inlined into os_getegid_impl 
os_getegid_impl
5917
}
5918
#endif /* HAVE_GETEGID */
5919

5920

5921
#ifdef HAVE_GETEUID
5922
/*[clinic input]
5923
os.geteuid
5924

5925
Return the current process's effective user id.
5926
[clinic start generated code]*/
5927

5928
static PyObject *
5929
os_geteuid_impl(PyObject *module)
5930
/*[clinic end generated code: output=ea1b60f0d6abb66e input=4644c662d3bd9f19]*/
5931
{
5932
    return _PyLong_FromUid(geteuid());
inline
                           
geteuid will not be inlined into os_geteuid_impl because its definition is unavailable 
os_geteuid_impl
inline
           
_PyLong_FromUid can be inlined into os_geteuid_impl with cost=45 (threshold=250) 
os_geteuid_impl
inline
           
_PyLong_FromUid inlined into os_geteuid_impl 
os_geteuid_impl
5933
}
5934
#endif /* HAVE_GETEUID */
5935

5936

5937
#ifdef HAVE_GETGID
5938
/*[clinic input]
5939
os.getgid
5940

5941
Return the current process's group id.
5942
[clinic start generated code]*/
5943

5944
static PyObject *
5945
os_getgid_impl(PyObject *module)
5946
/*[clinic end generated code: output=4f28ebc9d3e5dfcf input=58796344cd87c0f6]*/
5947
{
5948
    return _PyLong_FromGid(getgid());
inline
                           
getgid will not be inlined into os_getgid_impl because its definition is unavailable 
os_getgid_impl
inline
           
_PyLong_FromGid can be inlined into os_getgid_impl with cost=45 (threshold=250) 
os_getgid_impl
inline
           
_PyLong_FromGid inlined into os_getgid_impl 
os_getgid_impl
5949
}
5950
#endif /* HAVE_GETGID */
5951

5952

5953
#ifdef HAVE_GETPID
5954
/*[clinic input]
5955
os.getpid
5956

5957
Return the current process id.
5958
[clinic start generated code]*/
5959

5960
static PyObject *
5961
os_getpid_impl(PyObject *module)
5962
/*[clinic end generated code: output=9ea6fdac01ed2b3c input=5a9a00f0ab68aa00]*/
5963
{
5964
    return PyLong_FromPid(getpid());
inline
                          
getpid will not be inlined into os_getpid_impl because its definition is unavailable 
os_getpid_impl
inline
           
PyLong_FromLong will not be inlined into os_getpid_impl because its definition is unavailable 
os_getpid_impl
5965
}
5966
#endif /* HAVE_GETPID */
5967

5968
#ifdef HAVE_GETGROUPLIST
5969

5970
/* AC 3.5: funny apple logic below */
5971
PyDoc_STRVAR(posix_getgrouplist__doc__,
5972
"getgrouplist(user, group) -> list of groups to which a user belongs\n\n\
5973
Returns a list of groups to which a user belongs.\n\n\
5974
    user: username to lookup\n\
5975
    group: base group id of the user");
5976

5977
static PyObject *
5978
posix_getgrouplist(PyObject *self, PyObject *args)
5979
{
5980
#ifdef NGROUPS_MAX
5981
#define MAX_GROUPS NGROUPS_MAX
5982
#else
5983
    /* defined to be 16 on Solaris7, so this should be a small number */
5984
#define MAX_GROUPS 64
5985
#endif
5986

5987
    const char *user;
5988
    int i, ngroups;
5989
    PyObject *list;
5990
#ifdef __APPLE__
5991
    int *groups, basegid;
5992
#else
5993
    gid_t *groups, basegid;
5994
#endif
5995
    ngroups = MAX_GROUPS;
5996

5997
#ifdef __APPLE__
5998
    if (!PyArg_ParseTuple(args, "si:getgrouplist", &user, &basegid))
5999
        return NULL;
6000
#else
6001
    if (!PyArg_ParseTuple(args, "sO&:getgrouplist", &user,
inline
         
_PyArg_ParseTuple_SizeT will not be inlined into posix_getgrouplist because its definition is unavailable 
posix_getgrouplist
6002
                          _Py_Gid_Converter, &basegid))
6003
        return NULL;
6004
#endif
6005

6006
#ifdef __APPLE__
6007
    groups = PyMem_New(int, ngroups);
6008
#else
6009
    groups = PyMem_New(gid_t, ngroups);
inline
             
PyMem_Malloc will not be inlined into posix_getgrouplist because its definition is unavailable 
posix_getgrouplist
gvn
             
load of type i32 eliminated in favor of 65536 
posix_getgrouplist
6010
#endif
6011
    if (groups == NULL)
6012
        return PyErr_NoMemory();
inline
               
PyErr_NoMemory will not be inlined into posix_getgrouplist because its definition is unavailable 
posix_getgrouplist
6013

6014
    if (getgrouplist(user, basegid, groups, &ngroups) == -1) {
inline
        
getgrouplist will not be inlined into posix_getgrouplist because its definition is unavailable 
posix_getgrouplist
gvn
                     
load of type i8* not eliminated because it is clobbered by call 
posix_getgrouplist
gvn
                           
load of type i32 not eliminated because it is clobbered by call 
posix_getgrouplist
6015
        PyMem_Del(groups);
inline
        
PyMem_Free will not be inlined into posix_getgrouplist because its definition is unavailable 
posix_getgrouplist
6016
        return posix_error();
inline
               
posix_error can be inlined into posix_getgrouplist with cost=10 (threshold=375) 
posix_getgrouplist
inline
               
posix_error inlined into posix_getgrouplist 
posix_getgrouplist
6017
    }
6018

6019
    list = PyList_New(ngroups);
inline
           
PyList_New will not be inlined into posix_getgrouplist because its definition is unavailable 
posix_getgrouplist
gvn
                      
load of type i32 not eliminated in favor of store because it is clobbered by call 
posix_getgrouplist
6020
    if (list == NULL) {
6021
        PyMem_Del(groups);
inline
        
PyMem_Free will not be inlined into posix_getgrouplist because its definition is unavailable 
posix_getgrouplist
6022
        return NULL;
6023
    }
6024

6025
    for (i = 0; i < ngroups; i++) {
licm
                    
failed to move load with loop-invariant address because the loop may invalidate its value 
posix_getgrouplist
gvn
                    
load of type i32 not eliminated because it is clobbered by call 
posix_getgrouplist
loop-vectorize
    
loop not vectorized: loop control flow is not understood by vectorizer 
posix_getgrouplist
loop-vectorize
    
loop not vectorized 
posix_getgrouplist
6026
#ifdef __APPLE__
6027
        PyObject *o = PyLong_FromUnsignedLong((unsigned long)groups[i]);
6028
#else
6029
        PyObject *o = _PyLong_FromGid(groups[i]);
inline
                      
_PyLong_FromGid can be inlined into posix_getgrouplist with cost=45 (threshold=250) 
posix_getgrouplist
inline
                      
_PyLong_FromGid inlined into posix_getgrouplist 
posix_getgrouplist
gvn
                                      
load of type i32 not eliminated because it is clobbered by call 
posix_getgrouplist
6030
#endif
6031
        if (o == NULL) {
6032
            Py_DECREF(list);
gvn
            
load of type i64 not eliminated because it is clobbered by call 
posix_getgrouplist
6033
            PyMem_Del(groups);
inline
            
PyMem_Free will not be inlined into posix_getgrouplist because its definition is unavailable 
posix_getgrouplist
6034
            return NULL;
6035
        }
6036
        PyList_SET_ITEM(list, i, o);
licm
        
hosting getelementptr 
posix_getgrouplist
licm
        
failed to move load with loop-invariant address because the loop may invalidate its value 
posix_getgrouplist
gvn
        
load of type %struct._object** not eliminated because it is clobbered by call 
posix_getgrouplist
6037
    }
6038

6039
    PyMem_Del(groups);
inline
    
PyMem_Free will not be inlined into posix_getgrouplist because its definition is unavailable 
posix_getgrouplist
6040

6041
    return list;
6042
}
6043
#endif /* HAVE_GETGROUPLIST */
6044

6045

6046
#ifdef HAVE_GETGROUPS
6047
/*[clinic input]
6048
os.getgroups
6049

6050
Return list of supplemental group IDs for the process.
6051
[clinic start generated code]*/
6052

6053
static PyObject *
6054
os_getgroups_impl(PyObject *module)
6055
/*[clinic end generated code: output=42b0c17758561b56 input=d3f109412e6a155c]*/
6056
{
6057
    PyObject *result = NULL;
6058

6059
#ifdef NGROUPS_MAX
6060
#define MAX_GROUPS NGROUPS_MAX
6061
#else
6062
    /* defined to be 16 on Solaris7, so this should be a small number */
6063
#define MAX_GROUPS 64
6064
#endif
6065
    gid_t grouplist[MAX_GROUPS];
6066

6067
    /* On MacOSX getgroups(2) can return more than MAX_GROUPS results
6068
     * This is a helper variable to store the intermediate result when
6069
     * that happens.
6070
     *
6071
     * To keep the code readable the OSX behaviour is unconditional,
6072
     * according to the POSIX spec this should be safe on all unix-y
6073
     * systems.
6074
     */
6075
    gid_t* alt_grouplist = grouplist;
6076
    int n;
6077

6078
#ifdef __APPLE__
6079
    /* Issue #17557: As of OS X 10.8, getgroups(2) no longer raises EINVAL if
6080
     * there are more groups than can fit in grouplist.  Therefore, on OS X
6081
     * always first call getgroups with length 0 to get the actual number
6082
     * of groups.
6083
     */
6084
    n = getgroups(0, NULL);
6085
    if (n < 0) {
6086
        return posix_error();
6087
    } else if (n <= MAX_GROUPS) {
6088
        /* groups will fit in existing array */
6089
        alt_grouplist = grouplist;
6090
    } else {
6091
        alt_grouplist = PyMem_New(gid_t, n);
6092
        if (alt_grouplist == NULL) {
6093
            errno = EINVAL;
6094
            return posix_error();
6095
        }
6096
    }
6097

6098
    n = getgroups(n, alt_grouplist);
6099
    if (n == -1) {
6100
        if (alt_grouplist != grouplist) {
6101
            PyMem_Free(alt_grouplist);
6102
        }
6103
        return posix_error();
6104
    }
6105
#else
6106
    n = getgroups(MAX_GROUPS, grouplist);
inline
        
getgroups will not be inlined into os_getgroups_impl because its definition is unavailable 
os_getgroups_impl
6107
    if (n < 0) {
6108
        if (errno == EINVAL) {
inline
            
__errno_location will not be inlined into os_getgroups_impl because its definition is unavailable 
os_getgroups_impl
6109
            n = getgroups(0, NULL);
inline
                
getgroups will not be inlined into os_getgroups_impl because its definition is unavailable 
os_getgroups_impl
6110
            if (n == -1) {
6111
                return posix_error();
inline
                       
posix_error can be inlined into os_getgroups_impl with cost=10 (threshold=375) 
os_getgroups_impl
inline
                       
posix_error inlined into os_getgroups_impl 
os_getgroups_impl
6112
            }
6113
            if (n == 0) {
6114
                /* Avoid malloc(0) */
6115
                alt_grouplist = grouplist;
6116
            } else {
6117
                alt_grouplist = PyMem_New(gid_t, n);
inline
                                
PyMem_Malloc will not be inlined into os_getgroups_impl because its definition is unavailable 
os_getgroups_impl
6118
                if (alt_grouplist == NULL) {
6119
                    errno = EINVAL;
6120
                    return posix_error();
inline
                           
posix_error can be inlined into os_getgroups_impl with cost=10 (threshold=375) 
os_getgroups_impl
inline
                           
posix_error inlined into os_getgroups_impl 
os_getgroups_impl
6121
                }
6122
                n = getgroups(n, alt_grouplist);
inline
                    
getgroups will not be inlined into os_getgroups_impl because its definition is unavailable 
os_getgroups_impl
6123
                if (n == -1) {
6124
                    PyMem_Free(alt_grouplist);
inline
                    
PyMem_Free will not be inlined into os_getgroups_impl because its definition is unavailable 
os_getgroups_impl
6125
                    return posix_error();
inline
                           
posix_error can be inlined into os_getgroups_impl with cost=10 (threshold=375) 
os_getgroups_impl
inline
                           
posix_error inlined into os_getgroups_impl 
os_getgroups_impl
6126
                }
6127
            }
6128
        } else {
6129
            return posix_error();
inline
                   
posix_error can be inlined into os_getgroups_impl with cost=10 (threshold=375) 
os_getgroups_impl
inline
                   
posix_error inlined into os_getgroups_impl 
os_getgroups_impl
6130
        }
6131
    }
6132
#endif
6133

6134
    result = PyList_New(n);
inline
             
PyList_New will not be inlined into os_getgroups_impl because its definition is unavailable 
os_getgroups_impl
6135
    if (result != NULL) {
6136
        int i;
6137
        for (i = 0; i < n; ++i) {
loop-vectorize
        
loop not vectorized: loop control flow is not understood by vectorizer 
os_getgroups
loop-vectorize
        
loop not vectorized 
os_getgroups
6138
            PyObject *o = _PyLong_FromGid(alt_grouplist[i]);
inline
                          
_PyLong_FromGid can be inlined into os_getgroups_impl with cost=45 (threshold=250) 
os_getgroups_impl
inline
                          
_PyLong_FromGid inlined into os_getgroups_impl 
os_getgroups_impl
gvn
                                          
load of type i32 not eliminated because it is clobbered by call 
os_getgroups_impl
gvn
                                          
load of type i32 not eliminated because it is clobbered by call 
os_getgroups
6139
            if (o == NULL) {
6140
                Py_DECREF(result);
gvn
                
load of type i64 not eliminated because it is clobbered by call 
os_getgroups_impl
gvn
                
load of type i64 not eliminated because it is clobbered by call 
os_getgroups
6141
                result = NULL;
6142
                break;
6143
            }
6144
            PyList_SET_ITEM(result, i, o);
licm
            
hosting getelementptr 
os_getgroups_impl
licm
            
failed to move load with loop-invariant address because the loop may invalidate its value 
os_getgroups_impl
gvn
            
load of type %struct._object** not eliminated because it is clobbered by call 
os_getgroups_impl
licm
            
failed to move load with loop-invariant address because the loop may invalidate its value 
os_getgroups
gvn
            
load of type %struct._object** not eliminated because it is clobbered by call 
os_getgroups
6145
        }
6146
    }
6147

6148
    if (alt_grouplist != grouplist) {
6149
        PyMem_Free(alt_grouplist);
inline
        
PyMem_Free will not be inlined into os_getgroups_impl because its definition is unavailable 
os_getgroups_impl
6150
    }
6151

6152
    return result;
6153
}
6154
#endif /* HAVE_GETGROUPS */
6155

6156
#ifdef HAVE_INITGROUPS
6157
PyDoc_STRVAR(posix_initgroups__doc__,
6158
"initgroups(username, gid) -> None\n\n\
6159
Call the system initgroups() to initialize the group access list with all of\n\
6160
the groups of which the specified username is a member, plus the specified\n\
6161
group id.");
6162

6163
/* AC 3.5: funny apple logic */
6164
static PyObject *
6165
posix_initgroups(PyObject *self, PyObject *args)
6166
{
6167
    PyObject *oname;
6168
    const char *username;
6169
    int res;
6170
#ifdef __APPLE__
6171
    int gid;
6172
#else
6173
    gid_t gid;
6174
#endif
6175

6176
#ifdef __APPLE__
6177
    if (!PyArg_ParseTuple(args, "O&i:initgroups",
6178
                          PyUnicode_FSConverter, &oname,
6179
                          &gid))
6180
#else
6181
    if (!PyArg_ParseTuple(args, "O&O&:initgroups",
inline
         
_PyArg_ParseTuple_SizeT will not be inlined into posix_initgroups because its definition is unavailable 
posix_initgroups
6182
                          PyUnicode_FSConverter, &oname,
6183
                          _Py_Gid_Converter, &gid))
6184
#endif
6185
        return NULL;
6186
    username = PyBytes_AS_STRING(oname);
gvn
               
load of type %struct.PyBytesObject* not eliminated because it is clobbered by call 
posix_initgroups
6187

6188
    res = initgroups(username, gid);
inline
          
initgroups will not be inlined into posix_initgroups because its definition is unavailable 
posix_initgroups
gvn
                               
load of type i32 not eliminated because it is clobbered by call 
posix_initgroups
6189
    Py_DECREF(oname);
gvn
    
load of type %struct._object* not eliminated because it is clobbered by call 
posix_initgroups
6190
    if (res == -1)
6191
        return PyErr_SetFromErrno(PyExc_OSError);
inline
               
PyErr_SetFromErrno will not be inlined into posix_initgroups because its definition is unavailable 
posix_initgroups
gvn
                                  
load of type %struct._object* not eliminated because it is clobbered by call 
posix_initgroups
6192

6193
    Py_INCREF(Py_None);
gvn
    
load of type i64 not eliminated because it is clobbered by call 
posix_initgroups
6194
    return Py_None;
6195
}
6196
#endif /* HAVE_INITGROUPS */
6197

6198

6199
#ifdef HAVE_GETPGID
6200
/*[clinic input]
6201
os.getpgid
6202

6203
    pid: pid_t
6204

6205
Call the system call getpgid(), and return the result.
6206
[clinic start generated code]*/
6207

6208
static PyObject *
6209
os_getpgid_impl(PyObject *module, pid_t pid)
6210
/*[clinic end generated code: output=1db95a97be205d18 input=39d710ae3baaf1c7]*/
6211
{
6212
    pid_t pgid = getpgid(pid);
inline
                 
getpgid will not be inlined into os_getpgid_impl because its definition is unavailable 
os_getpgid_impl
6213
    if (pgid < 0)
6214
        return posix_error();
inline
               
posix_error can be inlined into os_getpgid_impl with cost=10 (threshold=375) 
os_getpgid_impl
inline
               
posix_error inlined into os_getpgid_impl 
os_getpgid_impl
6215
    return PyLong_FromPid(pgid);
inline
           
PyLong_FromLong will not be inlined into os_getpgid_impl because its definition is unavailable 
os_getpgid_impl
6216
}
6217
#endif /* HAVE_GETPGID */
6218

6219

6220
#ifdef HAVE_GETPGRP
6221
/*[clinic input]
6222
os.getpgrp
6223

6224
Return the current process group id.
6225
[clinic start generated code]*/
6226

6227
static PyObject *
6228
os_getpgrp_impl(PyObject *module)
6229
/*[clinic end generated code: output=c4fc381e51103cf3 input=6846fb2bb9a3705e]*/
6230
{
6231
#ifdef GETPGRP_HAVE_ARG
6232
    return PyLong_FromPid(getpgrp(0));
6233
#else /* GETPGRP_HAVE_ARG */
6234
    return PyLong_FromPid(getpgrp());
inline
                          
getpgrp will not be inlined into os_getpgrp_impl because its definition is unavailable 
os_getpgrp_impl
inline
           
PyLong_FromLong will not be inlined into os_getpgrp_impl because its definition is unavailable 
os_getpgrp_impl
6235
#endif /* GETPGRP_HAVE_ARG */
6236
}
6237
#endif /* HAVE_GETPGRP */
6238

6239

6240
#ifdef HAVE_SETPGRP
6241
/*[clinic input]
6242
os.setpgrp
6243

6244
Make the current process the leader of its process group.
6245
[clinic start generated code]*/
6246

6247
static PyObject *
6248
os_setpgrp_impl(PyObject *module)
6249
/*[clinic end generated code: output=2554735b0a60f0a0 input=1f0619fcb5731e7e]*/
6250
{
6251
#ifdef SETPGRP_HAVE_ARG
6252
    if (setpgrp(0, 0) < 0)
6253
#else /* SETPGRP_HAVE_ARG */
6254
    if (setpgrp() < 0)
inline
        
setpgrp will not be inlined into os_setpgrp_impl because its definition is unavailable 
os_setpgrp_impl
6255
#endif /* SETPGRP_HAVE_ARG */
6256
        return posix_error();
inline
               
posix_error can be inlined into os_setpgrp_impl with cost=10 (threshold=375) 
os_setpgrp_impl
inline
               
posix_error inlined into os_setpgrp_impl 
os_setpgrp_impl
6257
    Py_INCREF(Py_None);
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_setpgrp_impl
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_setpgrp
6258
    return Py_None;
6259
}
6260
#endif /* HAVE_SETPGRP */
6261

6262
#ifdef HAVE_GETPPID
6263

6264
#ifdef MS_WINDOWS
6265
#include <tlhelp32.h>
6266

6267
static PyObject*
6268
win32_getppid()
6269
{
6270
    HANDLE snapshot;
6271
    pid_t mypid;
6272
    PyObject* result = NULL;
6273
    BOOL have_record;
6274
    PROCESSENTRY32 pe;
6275

6276
    mypid = getpid(); /* This function never fails */
6277

6278
    snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
6279
    if (snapshot == INVALID_HANDLE_VALUE)
6280
        return PyErr_SetFromWindowsErr(GetLastError());
6281

6282
    pe.dwSize = sizeof(pe);
6283
    have_record = Process32First(snapshot, &pe);
6284
    while (have_record) {
6285
        if (mypid == (pid_t)pe.th32ProcessID) {
6286
            /* We could cache the ulong value in a static variable. */
6287
            result = PyLong_FromPid((pid_t)pe.th32ParentProcessID);
6288
            break;
6289
        }
6290

6291
        have_record = Process32Next(snapshot, &pe);
6292
    }
6293

6294
    /* If our loop exits and our pid was not found (result will be NULL)
6295
     * then GetLastError will return ERROR_NO_MORE_FILES. This is an
6296
     * error anyway, so let's raise it. */
6297
    if (!result)
6298
        result = PyErr_SetFromWindowsErr(GetLastError());
6299

6300
    CloseHandle(snapshot);
6301

6302
    return result;
6303
}
6304
#endif /*MS_WINDOWS*/
6305

6306

6307
/*[clinic input]
6308
os.getppid
6309

6310
Return the parent's process id.
6311

6312
If the parent process has already exited, Windows machines will still
6313
return its id; others systems will return the id of the 'init' process (1).
6314
[clinic start generated code]*/
6315

6316
static PyObject *
6317
os_getppid_impl(PyObject *module)
6318
/*[clinic end generated code: output=43b2a946a8c603b4 input=e637cb87539c030e]*/
6319
{
6320
#ifdef MS_WINDOWS
6321
    return win32_getppid();
6322
#else
6323
    return PyLong_FromPid(getppid());
inline
                          
getppid will not be inlined into os_getppid_impl because its definition is unavailable 
os_getppid_impl
inline
           
PyLong_FromLong will not be inlined into os_getppid_impl because its definition is unavailable 
os_getppid_impl
6324
#endif
6325
}
6326
#endif /* HAVE_GETPPID */
6327

6328

6329
#ifdef HAVE_GETLOGIN
6330
/*[clinic input]
6331
os.getlogin
6332

6333
Return the actual login name.
6334
[clinic start generated code]*/
6335

6336
static PyObject *
6337
os_getlogin_impl(PyObject *module)
6338
/*[clinic end generated code: output=a32e66a7e5715dac input=2a21ab1e917163df]*/
6339
{
6340
    PyObject *result = NULL;
6341
#ifdef MS_WINDOWS
6342
    wchar_t user_name[UNLEN + 1];
6343
    DWORD num_chars = Py_ARRAY_LENGTH(user_name);
6344

6345
    if (GetUserNameW(user_name, &num_chars)) {
6346
        /* num_chars is the number of unicode chars plus null terminator */
6347
        result = PyUnicode_FromWideChar(user_name, num_chars - 1);
6348
    }
6349
    else
6350
        result = PyErr_SetFromWindowsErr(GetLastError());
6351
#else
6352
    char *name;
6353
    int old_errno = errno;
inline
                    
__errno_location will not be inlined into os_getlogin_impl because its definition is unavailable 
os_getlogin_impl
6354

6355
    errno = 0;
6356
    name = getlogin();
inline
           
getlogin will not be inlined into os_getlogin_impl because its definition is unavailable 
os_getlogin_impl
6357
    if (name == NULL) {
6358
        if (errno)
gvn
            
load of type i32 not eliminated because it is clobbered by call 
os_getlogin_impl
gvn
            
load of type i32 not eliminated because it is clobbered by call 
os_getlogin
6359
            posix_error();
inline
            
posix_error can be inlined into os_getlogin_impl with cost=10 (threshold=375) 
os_getlogin_impl
inline
            
posix_error inlined into os_getlogin_impl 
os_getlogin_impl
6360
        else
6361
            PyErr_SetString(PyExc_OSError, "unable to determine login name");
inline
            
PyErr_SetString will not be inlined into os_getlogin_impl because its definition is unavailable 
os_getlogin_impl
6362
    }
6363
    else
6364
        result = PyUnicode_DecodeFSDefault(name);
inline
                 
PyUnicode_DecodeFSDefault will not be inlined into os_getlogin_impl because its definition is unavailable 
os_getlogin_impl
6365
    errno = old_errno;
6366
#endif
6367
    return result;
6368
}
6369
#endif /* HAVE_GETLOGIN */
6370

6371

6372
#ifdef HAVE_GETUID
6373
/*[clinic input]
6374
os.getuid
6375

6376
Return the current process's user id.
6377
[clinic start generated code]*/
6378

6379
static PyObject *
6380
os_getuid_impl(PyObject *module)
6381
/*[clinic end generated code: output=415c0b401ebed11a input=b53c8b35f110a516]*/
6382
{
6383
    return _PyLong_FromUid(getuid());
inline
                           
getuid will not be inlined into os_getuid_impl because its definition is unavailable 
os_getuid_impl
inline
           
_PyLong_FromUid can be inlined into os_getuid_impl with cost=45 (threshold=250) 
os_getuid_impl
inline
           
_PyLong_FromUid inlined into os_getuid_impl 
os_getuid_impl
6384
}
6385
#endif /* HAVE_GETUID */
6386

6387

6388
#ifdef MS_WINDOWS
6389
#define HAVE_KILL
6390
#endif /* MS_WINDOWS */
6391

6392
#ifdef HAVE_KILL
6393
/*[clinic input]
6394
os.kill
6395

6396
    pid: pid_t
6397
    signal: Py_ssize_t
6398
    /
6399

6400
Kill a process with a signal.
6401
[clinic start generated code]*/
6402

6403
static PyObject *
6404
os_kill_impl(PyObject *module, pid_t pid, Py_ssize_t signal)
6405
/*[clinic end generated code: output=8e346a6701c88568 input=61a36b86ca275ab9]*/
6406
#ifndef MS_WINDOWS
6407
{
6408
    if (kill(pid, (int)signal) == -1)
inline
        
kill will not be inlined into os_kill_impl because its definition is unavailable 
os_kill_impl
6409
        return posix_error();
inline
               
posix_error can be inlined into os_kill_impl with cost=10 (threshold=375) 
os_kill_impl
inline
               
posix_error inlined into os_kill_impl 
os_kill_impl
6410
    Py_RETURN_NONE;
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_kill_impl
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_kill
6411
}
6412
#else /* !MS_WINDOWS */
6413
{
6414
    PyObject *result;
6415
    DWORD sig = (DWORD)signal;
6416
    DWORD err;
6417
    HANDLE handle;
6418

6419
    /* Console processes which share a common console can be sent CTRL+C or
6420
       CTRL+BREAK events, provided they handle said events. */
6421
    if (sig == CTRL_C_EVENT || sig == CTRL_BREAK_EVENT) {
6422
        if (GenerateConsoleCtrlEvent(sig, (DWORD)pid) == 0) {
6423
            err = GetLastError();
6424
            PyErr_SetFromWindowsErr(err);
6425
        }
6426
        else
6427
            Py_RETURN_NONE;
6428
    }
6429

6430
    /* If the signal is outside of what GenerateConsoleCtrlEvent can use,
6431
       attempt to open and terminate the process. */
6432
    handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, (DWORD)pid);
6433
    if (handle == NULL) {
6434
        err = GetLastError();
6435
        return PyErr_SetFromWindowsErr(err);
6436
    }
6437

6438
    if (TerminateProcess(handle, sig) == 0) {
6439
        err = GetLastError();
6440
        result = PyErr_SetFromWindowsErr(err);
6441
    } else {
6442
        Py_INCREF(Py_None);
6443
        result = Py_None;
6444
    }
6445

6446
    CloseHandle(handle);
6447
    return result;
6448
}
6449
#endif /* !MS_WINDOWS */
6450
#endif /* HAVE_KILL */
6451

6452

6453
#ifdef HAVE_KILLPG
6454
/*[clinic input]
6455
os.killpg
6456

6457
    pgid: pid_t
6458
    signal: int
6459
    /
6460

6461
Kill a process group with a signal.
6462
[clinic start generated code]*/
6463

6464
static PyObject *
6465
os_killpg_impl(PyObject *module, pid_t pgid, int signal)
6466
/*[clinic end generated code: output=6dbcd2f1fdf5fdba input=38b5449eb8faec19]*/
6467
{
6468
    /* XXX some man pages make the `pgid` parameter an int, others
6469
       a pid_t. Since getpgrp() returns a pid_t, we assume killpg should
6470
       take the same type. Moreover, pid_t is always at least as wide as
6471
       int (else compilation of this module fails), which is safe. */
6472
    if (killpg(pgid, signal) == -1)
inline
        
killpg will not be inlined into os_killpg_impl because its definition is unavailable 
os_killpg_impl
6473
        return posix_error();
inline
               
posix_error can be inlined into os_killpg_impl with cost=10 (threshold=375) 
os_killpg_impl
inline
               
posix_error inlined into os_killpg_impl 
os_killpg_impl
6474
    Py_RETURN_NONE;
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_killpg_impl
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_killpg
6475
}
6476
#endif /* HAVE_KILLPG */
6477

6478

6479
#ifdef HAVE_PLOCK
6480
#ifdef HAVE_SYS_LOCK_H
6481
#include <sys/lock.h>
6482
#endif
6483

6484
/*[clinic input]
6485
os.plock
6486
    op: int
6487
    /
6488

6489
Lock program segments into memory.");
6490
[clinic start generated code]*/
6491

6492
static PyObject *
6493
os_plock_impl(PyObject *module, int op)
6494
/*[clinic end generated code: output=81424167033b168e input=e6e5e348e1525f60]*/
6495
{
6496
    if (plock(op) == -1)
6497
        return posix_error();
6498
    Py_RETURN_NONE;
6499
}
6500
#endif /* HAVE_PLOCK */
6501

6502

6503
#ifdef HAVE_SETUID
6504
/*[clinic input]
6505
os.setuid
6506

6507
    uid: uid_t
6508
    /
6509

6510
Set the current process's user id.
6511
[clinic start generated code]*/
6512

6513
static PyObject *
6514
os_setuid_impl(PyObject *module, uid_t uid)
6515
/*[clinic end generated code: output=a0a41fd0d1ec555f input=c921a3285aa22256]*/
6516
{
6517
    if (setuid(uid) < 0)
inline
        
setuid will not be inlined into os_setuid_impl because its definition is unavailable 
os_setuid_impl
6518
        return posix_error();
inline
               
posix_error can be inlined into os_setuid_impl with cost=10 (threshold=375) 
os_setuid_impl
inline
               
posix_error inlined into os_setuid_impl 
os_setuid_impl
6519
    Py_RETURN_NONE;
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_setuid_impl
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_setuid
6520
}
6521
#endif /* HAVE_SETUID */
6522

6523

6524
#ifdef HAVE_SETEUID
6525
/*[clinic input]
6526
os.seteuid
6527

6528
    euid: uid_t
6529
    /
6530

6531
Set the current process's effective user id.
6532
[clinic start generated code]*/
6533

6534
static PyObject *
6535
os_seteuid_impl(PyObject *module, uid_t euid)
6536
/*[clinic end generated code: output=102e3ad98361519a input=ba93d927e4781aa9]*/
6537
{
6538
    if (seteuid(euid) < 0)
inline
        
seteuid will not be inlined into os_seteuid_impl because its definition is unavailable 
os_seteuid_impl
6539
        return posix_error();
inline
               
posix_error can be inlined into os_seteuid_impl with cost=10 (threshold=375) 
os_seteuid_impl
inline
               
posix_error inlined into os_seteuid_impl 
os_seteuid_impl
6540
    Py_RETURN_NONE;
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_seteuid_impl
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_seteuid
6541
}
6542
#endif /* HAVE_SETEUID */
6543

6544

6545
#ifdef HAVE_SETEGID
6546
/*[clinic input]
6547
os.setegid
6548

6549
    egid: gid_t
6550
    /
6551

6552
Set the current process's effective group id.
6553
[clinic start generated code]*/
6554

6555
static PyObject *
6556
os_setegid_impl(PyObject *module, gid_t egid)
6557
/*[clinic end generated code: output=4e4b825a6a10258d input=4080526d0ccd6ce3]*/
6558
{
6559
    if (setegid(egid) < 0)
inline
        
setegid will not be inlined into os_setegid_impl because its definition is unavailable 
os_setegid_impl
6560
        return posix_error();
inline
               
posix_error can be inlined into os_setegid_impl with cost=10 (threshold=375) 
os_setegid_impl
inline
               
posix_error inlined into os_setegid_impl 
os_setegid_impl
6561
    Py_RETURN_NONE;
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_setegid_impl
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_setegid
6562
}
6563
#endif /* HAVE_SETEGID */
6564

6565

6566
#ifdef HAVE_SETREUID
6567
/*[clinic input]
6568
os.setreuid
6569

6570
    ruid: uid_t
6571
    euid: uid_t
6572
    /
6573

6574
Set the current process's real and effective user ids.
6575
[clinic start generated code]*/
6576

6577
static PyObject *
6578
os_setreuid_impl(PyObject *module, uid_t ruid, uid_t euid)
6579
/*[clinic end generated code: output=62d991210006530a input=0ca8978de663880c]*/
6580
{
6581
    if (setreuid(ruid, euid) < 0) {
inline
        
setreuid will not be inlined into os_setreuid_impl because its definition is unavailable 
os_setreuid_impl
6582
        return posix_error();
inline
               
posix_error can be inlined into os_setreuid_impl with cost=10 (threshold=375) 
os_setreuid_impl
inline
               
posix_error inlined into os_setreuid_impl 
os_setreuid_impl
6583
    } else {
6584
        Py_INCREF(Py_None);
gvn
        
load of type i64 not eliminated because it is clobbered by call 
os_setreuid_impl
gvn
        
load of type i64 not eliminated because it is clobbered by call 
os_setreuid
6585
        return Py_None;
6586
    }
6587
}
6588
#endif /* HAVE_SETREUID */
6589

6590

6591
#ifdef HAVE_SETREGID
6592
/*[clinic input]
6593
os.setregid
6594

6595
    rgid: gid_t
6596
    egid: gid_t
6597
    /
6598

6599
Set the current process's real and effective group ids.
6600
[clinic start generated code]*/
6601

6602
static PyObject *
6603
os_setregid_impl(PyObject *module, gid_t rgid, gid_t egid)
6604
/*[clinic end generated code: output=aa803835cf5342f3 input=c59499f72846db78]*/
6605
{
6606
    if (setregid(rgid, egid) < 0)
inline
        
setregid will not be inlined into os_setregid_impl because its definition is unavailable 
os_setregid_impl
6607
        return posix_error();
inline
               
posix_error can be inlined into os_setregid_impl with cost=10 (threshold=375) 
os_setregid_impl
inline
               
posix_error inlined into os_setregid_impl 
os_setregid_impl
6608
    Py_RETURN_NONE;
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_setregid_impl
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_setregid
6609
}
6610
#endif /* HAVE_SETREGID */
6611

6612

6613
#ifdef HAVE_SETGID
6614
/*[clinic input]
6615
os.setgid
6616
    gid: gid_t
6617
    /
6618

6619
Set the current process's group id.
6620
[clinic start generated code]*/
6621

6622
static PyObject *
6623
os_setgid_impl(PyObject *module, gid_t gid)
6624
/*[clinic end generated code: output=bdccd7403f6ad8c3 input=27d30c4059045dc6]*/
6625
{
6626
    if (setgid(gid) < 0)
inline
        
setgid will not be inlined into os_setgid_impl because its definition is unavailable 
os_setgid_impl
6627
        return posix_error();
inline
               
posix_error can be inlined into os_setgid_impl with cost=10 (threshold=375) 
os_setgid_impl
inline
               
posix_error inlined into os_setgid_impl 
os_setgid_impl
6628
    Py_RETURN_NONE;
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_setgid_impl
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_setgid
6629
}
6630
#endif /* HAVE_SETGID */
6631

6632

6633
#ifdef HAVE_SETGROUPS
6634
/*[clinic input]
6635
os.setgroups
6636

6637
    groups: object
6638
    /
6639

6640
Set the groups of the current process to list.
6641
[clinic start generated code]*/
6642

6643
static PyObject *
6644
os_setgroups(PyObject *module, PyObject *groups)
6645
/*[clinic end generated code: output=3fcb32aad58c5ecd input=fa742ca3daf85a7e]*/
6646
{
6647
    int i, len;
6648
    gid_t grouplist[MAX_GROUPS];
6649

6650
    if (!PySequence_Check(groups)) {
inline
         
PySequence_Check will not be inlined into os_setgroups because its definition is unavailable 
os_setgroups
6651
        PyErr_SetString(PyExc_TypeError, "setgroups argument must be a sequence");
inline
        
PyErr_SetString will not be inlined into os_setgroups because its definition is unavailable 
os_setgroups
gvn
                        
load of type %struct._object* not eliminated because it is clobbered by call 
os_setgroups
6652
        return NULL;
6653
    }
6654
    len = PySequence_Size(groups);
inline
          
PySequence_Size will not be inlined into os_setgroups because its definition is unavailable 
os_setgroups
6655
    if (len > MAX_GROUPS) {
6656
        PyErr_SetString(PyExc_ValueError, "too many groups");
inline
        
PyErr_SetString will not be inlined into os_setgroups because its definition is unavailable 
os_setgroups
gvn
                        
load of type %struct._object* not eliminated because it is clobbered by call 
os_setgroups
6657
        return NULL;
6658
    }
6659
    for(i = 0; i < len; i++) {
loop-vectorize
    
loop not vectorized: loop control flow is not understood by vectorizer 
os_setgroups
loop-vectorize
    
loop not vectorized 
os_setgroups
6660
        PyObject *elem;
6661
        elem = PySequence_GetItem(groups, i);
inline
               
PySequence_GetItem will not be inlined into os_setgroups because its definition is unavailable 
os_setgroups
6662
        if (!elem)
6663
            return NULL;
6664
        if (!PyLong_Check(elem)) {
gvn
             
load of type %struct._typeobject* not eliminated because it is clobbered by call 
os_setgroups
6665
            PyErr_SetString(PyExc_TypeError,
inline
            
PyErr_SetString will not be inlined into os_setgroups because its definition is unavailable 
os_setgroups
gvn
                            
load of type %struct._object* not eliminated because it is clobbered by call 
os_setgroups
6666
                            "groups must be integers");
6667
            Py_DECREF(elem);
gvn
            
load of type i64 not eliminated because it is clobbered by call 
os_setgroups
6668
            return NULL;
6669
        } else {
6670
            if (!_Py_Gid_Converter(elem, &grouplist[i])) {
inline
                 
_Py_Gid_Converter too costly to inline (cost=545, threshold=250) 
os_setgroups
inline
                 
_Py_Gid_Converter will not be inlined into os_setgroups 
os_setgroups
6671
                Py_DECREF(elem);
gvn
                
load of type %struct._typeobject* not eliminated in favor of load because it is clobbered by call 
os_setgroups
6672
                return NULL;
6673
            }
6674
        }
6675
        Py_DECREF(elem);
gvn
        
load of type i64 not eliminated because it is clobbered by call 
os_setgroups
6676
    }
6677

6678
    if (setgroups(len, grouplist) < 0)
inline
        
setgroups will not be inlined into os_setgroups because its definition is unavailable 
os_setgroups
6679
        return posix_error();
inline
               
posix_error can be inlined into os_setgroups with cost=10 (threshold=375) 
os_setgroups
inline
               
posix_error inlined into os_setgroups 
os_setgroups
6680
    Py_INCREF(Py_None);
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_setgroups
6681
    return Py_None;
6682
}
6683
#endif /* HAVE_SETGROUPS */
6684

6685
#if defined(HAVE_WAIT3) || defined(HAVE_WAIT4)
6686
static PyObject *
6687
wait_helper(pid_t pid, int status, struct rusage *ru)
6688
{
6689
    PyObject *result;
6690
    static PyObject *struct_rusage;
6691
    _Py_IDENTIFIER(struct_rusage);
6692

6693
    if (pid == -1)
6694
        return posix_error();
inline
               
posix_error can be inlined into wait_helper with cost=10 (threshold=375) 
wait_helper
inline
               
posix_error inlined into wait_helper 
wait_helper
6695

6696
    if (struct_rusage == NULL) {
6697
        PyObject *m = PyImport_ImportModuleNoBlock("resource");
inline
                      
PyImport_ImportModuleNoBlock will not be inlined into wait_helper because its definition is unavailable 
wait_helper
6698
        if (m == NULL)
6699
            return NULL;
6700
        struct_rusage = _PyObject_GetAttrId(m, &PyId_struct_rusage);
inline
                        
_PyObject_GetAttrId will not be inlined into wait_helper because its definition is unavailable 
wait_helper
6701
        Py_DECREF(m);
gvn
        
load of type i64 not eliminated because it is clobbered by call 
wait_helper
6702
        if (struct_rusage == NULL)
gvn
            
load of type %struct._object* not eliminated because it is clobbered by call 
wait_helper
gvn
            
load eliminated by PRE 
wait_helper
6703
            return NULL;
6704
    }
6705

6706
    /* XXX(nnorwitz): Copied (w/mods) from resource.c, there should be only one. */
6707
    result = PyStructSequence_New((PyTypeObject*) struct_rusage);
inline
             
PyStructSequence_New will not be inlined into wait_helper because its definition is unavailable 
wait_helper
gvn
                                                  
load of type %struct._typeobject* eliminated in favor of phi 
wait_helper
6708
    if (!result)
6709
        return NULL;
6710

6711
#ifndef doubletime
6712
#define doubletime(TV) ((double)(TV).tv_sec + (TV).tv_usec * 0.000001)
6713
#endif
6714

6715
    PyStructSequence_SET_ITEM(result, 0,
inline
    
PyFloat_FromDouble will not be inlined into wait_helper because its definition is unavailable 
wait_helper
gvn
    
load of type i64 not eliminated because it is clobbered by call 
wait_helper
6716
                              PyFloat_FromDouble(doubletime(ru->ru_utime)));
6717
    PyStructSequence_SET_ITEM(result, 1,
inline
    
PyFloat_FromDouble will not be inlined into wait_helper because its definition is unavailable 
wait_helper
gvn
    
load of type i64 not eliminated because it is clobbered by call 
wait_helper
6718
                              PyFloat_FromDouble(doubletime(ru->ru_stime)));
6719
#define SET_INT(result, index, value)\
6720
        PyStructSequence_SET_ITEM(result, index, PyLong_FromLong(value))
6721
    SET_INT(result, 2, ru->ru_maxrss);
inline
    
PyLong_FromLong will not be inlined into wait_helper because its definition is unavailable 
wait_helper
gvn
    
load of type i64 not eliminated because it is clobbered by call 
wait_helper
6722
    SET_INT(result, 3, ru->ru_ixrss);
inline
    
PyLong_FromLong will not be inlined into wait_helper because its definition is unavailable 
wait_helper
gvn
    
load of type i64 not eliminated because it is clobbered by call 
wait_helper
6723
    SET_INT(result, 4, ru->ru_idrss);
inline
    
PyLong_FromLong will not be inlined into wait_helper because its definition is unavailable 
wait_helper
gvn
    
load of type i64 not eliminated because it is clobbered by call 
wait_helper
6724
    SET_INT(result, 5, ru->ru_isrss);
inline
    
PyLong_FromLong will not be inlined into wait_helper because its definition is unavailable 
wait_helper
gvn
    
load of type i64 not eliminated because it is clobbered by call 
wait_helper
6725
    SET_INT(result, 6, ru->ru_minflt);
inline
    
PyLong_FromLong will not be inlined into wait_helper because its definition is unavailable 
wait_helper
gvn
    
load of type i64 not eliminated because it is clobbered by call 
wait_helper
6726
    SET_INT(result, 7, ru->ru_majflt);
inline
    
PyLong_FromLong will not be inlined into wait_helper because its definition is unavailable 
wait_helper
gvn
    
load of type i64 not eliminated because it is clobbered by call 
wait_helper
6727
    SET_INT(result, 8, ru->ru_nswap);
inline
    
PyLong_FromLong will not be inlined into wait_helper because its definition is unavailable 
wait_helper
gvn
    
load of type i64 not eliminated because it is clobbered by call 
wait_helper
6728
    SET_INT(result, 9, ru->ru_inblock);
inline
    
PyLong_FromLong will not be inlined into wait_helper because its definition is unavailable 
wait_helper
gvn
    
load of type i64 not eliminated because it is clobbered by call 
wait_helper
6729
    SET_INT(result, 10, ru->ru_oublock);
inline
    
PyLong_FromLong will not be inlined into wait_helper because its definition is unavailable 
wait_helper
gvn
    
load of type i64 not eliminated because it is clobbered by call 
wait_helper
6730
    SET_INT(result, 11, ru->ru_msgsnd);
inline
    
PyLong_FromLong will not be inlined into wait_helper because its definition is unavailable 
wait_helper
gvn
    
load of type i64 not eliminated because it is clobbered by call 
wait_helper
6731
    SET_INT(result, 12, ru->ru_msgrcv);
inline
    
PyLong_FromLong will not be inlined into wait_helper because its definition is unavailable 
wait_helper
gvn
    
load of type i64 not eliminated because it is clobbered by call 
wait_helper
6732
    SET_INT(result, 13, ru->ru_nsignals);
inline
    
PyLong_FromLong will not be inlined into wait_helper because its definition is unavailable 
wait_helper
gvn
    
load of type i64 not eliminated because it is clobbered by call 
wait_helper
6733
    SET_INT(result, 14, ru->ru_nvcsw);
inline
    
PyLong_FromLong will not be inlined into wait_helper because its definition is unavailable 
wait_helper
gvn
    
load of type i64 not eliminated because it is clobbered by call 
wait_helper
6734
    SET_INT(result, 15, ru->ru_nivcsw);
inline
    
PyLong_FromLong will not be inlined into wait_helper because its definition is unavailable 
wait_helper
gvn
    
load of type i64 not eliminated because it is clobbered by call 
wait_helper
6735
#undef SET_INT
6736

6737
    if (PyErr_Occurred()) {
inline
        
PyErr_Occurred will not be inlined into wait_helper because its definition is unavailable 
wait_helper
6738
        Py_DECREF(result);
gvn
        
load of type i64 not eliminated because it is clobbered by call 
wait_helper
6739
        return NULL;
6740
    }
6741

6742
    return Py_BuildValue("NiN", PyLong_FromPid(pid), status, result);
inline
                                
PyLong_FromLong will not be inlined into wait_helper because its definition is unavailable 
wait_helper
inline
           
_Py_BuildValue_SizeT will not be inlined into wait_helper because its definition is unavailable 
wait_helper
6743
}
6744
#endif /* HAVE_WAIT3 || HAVE_WAIT4 */
6745

6746

6747
#ifdef HAVE_WAIT3
6748
/*[clinic input]
6749
os.wait3
6750

6751
    options: int
6752
Wait for completion of a child process.
6753

6754
Returns a tuple of information about the child process:
6755
  (pid, status, rusage)
6756
[clinic start generated code]*/
6757

6758
static PyObject *
6759
os_wait3_impl(PyObject *module, int options)
6760
/*[clinic end generated code: output=92c3224e6f28217a input=8ac4c56956b61710]*/
6761
{
6762
    pid_t pid;
6763
    struct rusage ru;
6764
    int async_err = 0;
6765
    WAIT_TYPE status;
6766
    WAIT_STATUS_INT(status) = 0;
6767

6768
    do {
loop-vectorize
    
loop not vectorized: loop control flow is not understood by vectorizer 
os_wait3
loop-vectorize
    
loop not vectorized 
os_wait3
6769
        Py_BEGIN_ALLOW_THREADS
inline
        
PyEval_SaveThread will not be inlined into os_wait3_impl because its definition is unavailable 
os_wait3_impl
6770
        pid = wait3(&status, options, &ru);
inline
              
wait3 will not be inlined into os_wait3_impl because its definition is unavailable 
os_wait3_impl
licm
                    
hosting bitcast 
os_wait3_impl
6771
        Py_END_ALLOW_THREADS
inline
        
PyEval_RestoreThread will not be inlined into os_wait3_impl because its definition is unavailable 
os_wait3_impl
6772
    } while (pid < 0 && errno == EINTR && !(async_err = PyErr_CheckSignals()));
inline
                        
__errno_location will not be inlined into os_wait3_impl because its definition is unavailable 
os_wait3_impl
inline
                                                        
PyErr_CheckSignals will not be inlined into os_wait3_impl because its definition is unavailable 
os_wait3_impl
6773
    if (pid < 0)
6774
        return (!async_err) ? posix_error() : NULL;
inline
                              
posix_error can be inlined into os_wait3_impl with cost=10 (threshold=375) 
os_wait3_impl
inline
                              
posix_error inlined into os_wait3_impl 
os_wait3_impl
6775

6776
    return wait_helper(pid, WAIT_STATUS_INT(status), &ru);
inline
           
wait_helper too costly to inline (cost=655, threshold=625) 
os_wait3_impl
inline
           
wait_helper will not be inlined into os_wait3_impl 
os_wait3_impl
gvn
                            
load of type i32 not eliminated in favor of store because it is clobbered by call 
os_wait3_impl
inline
           
wait_helper too costly to inline (cost=655, threshold=625) 
os_wait3
inline
           
wait_helper will not be inlined into os_wait3 
os_wait3
gvn
                            
load of type i32 not eliminated in favor of store because it is clobbered by call 
os_wait3
6777
}
6778
#endif /* HAVE_WAIT3 */
6779

6780

6781
#ifdef HAVE_WAIT4
6782
/*[clinic input]
6783

6784
os.wait4
6785

6786
    pid: pid_t
6787
    options: int
6788

6789
Wait for completion of a specific child process.
6790

6791
Returns a tuple of information about the child process:
6792
  (pid, status, rusage)
6793
[clinic start generated code]*/
6794

6795
static PyObject *
6796
os_wait4_impl(PyObject *module, pid_t pid, int options)
6797
/*[clinic end generated code: output=66195aa507b35f70 input=d11deed0750600ba]*/
6798
{
6799
    pid_t res;
6800
    struct rusage ru;
6801
    int async_err = 0;
6802
    WAIT_TYPE status;
6803
    WAIT_STATUS_INT(status) = 0;
6804

6805
    do {
loop-vectorize
    
loop not vectorized: loop control flow is not understood by vectorizer 
os_wait4
loop-vectorize
    
loop not vectorized 
os_wait4
6806
        Py_BEGIN_ALLOW_THREADS
inline
        
PyEval_SaveThread will not be inlined into os_wait4_impl because its definition is unavailable 
os_wait4_impl
6807
        res = wait4(pid, &status, options, &ru);
inline
              
wait4 will not be inlined into os_wait4_impl because its definition is unavailable 
os_wait4_impl
licm
                         
hosting bitcast 
os_wait4_impl
6808
        Py_END_ALLOW_THREADS
inline
        
PyEval_RestoreThread will not be inlined into os_wait4_impl because its definition is unavailable 
os_wait4_impl
6809
    } while (res < 0 && errno == EINTR && !(async_err = PyErr_CheckSignals()));
inline
                        
__errno_location will not be inlined into os_wait4_impl because its definition is unavailable 
os_wait4_impl
inline
                                                        
PyErr_CheckSignals will not be inlined into os_wait4_impl because its definition is unavailable 
os_wait4_impl
6810
    if (res < 0)
6811
        return (!async_err) ? posix_error() : NULL;
inline
                              
posix_error can be inlined into os_wait4_impl with cost=10 (threshold=375) 
os_wait4_impl
inline
                              
posix_error inlined into os_wait4_impl 
os_wait4_impl
6812

6813
    return wait_helper(res, WAIT_STATUS_INT(status), &ru);
inline
           
wait_helper too costly to inline (cost=655, threshold=625) 
os_wait4_impl
inline
           
wait_helper will not be inlined into os_wait4_impl 
os_wait4_impl
gvn
                            
load of type i32 not eliminated in favor of store because it is clobbered by call 
os_wait4_impl
inline
           
wait_helper too costly to inline (cost=655, threshold=625) 
os_wait4
inline
           
wait_helper will not be inlined into os_wait4 
os_wait4
gvn
                            
load of type i32 not eliminated in favor of store because it is clobbered by call 
os_wait4
6814
}
6815
#endif /* HAVE_WAIT4 */
6816

6817

6818
#if defined(HAVE_WAITID) && !defined(__APPLE__)
6819
/*[clinic input]
6820
os.waitid
6821

6822
    idtype: idtype_t
6823
        Must be one of be P_PID, P_PGID or P_ALL.
6824
    id: id_t
6825
        The id to wait on.
6826
    options: int
6827
        Constructed from the ORing of one or more of WEXITED, WSTOPPED
6828
        or WCONTINUED and additionally may be ORed with WNOHANG or WNOWAIT.
6829
    /
6830

6831
Returns the result of waiting for a process or processes.
6832

6833
Returns either waitid_result or None if WNOHANG is specified and there are
6834
no children in a waitable state.
6835
[clinic start generated code]*/
6836

6837
static PyObject *
6838
os_waitid_impl(PyObject *module, idtype_t idtype, id_t id, int options)
6839
/*[clinic end generated code: output=5d2e1c0bde61f4d8 input=d8e7f76e052b7920]*/
6840
{
6841
    PyObject *result;
6842
    int res;
6843
    int async_err = 0;
6844
    siginfo_t si;
6845
    si.si_pid = 0;
6846

6847
    do {
loop-vectorize
    
loop not vectorized: loop control flow is not understood by vectorizer 
os_waitid
loop-vectorize
    
loop not vectorized 
os_waitid
6848
        Py_BEGIN_ALLOW_THREADS
inline
        
PyEval_SaveThread will not be inlined into os_waitid_impl because its definition is unavailable 
os_waitid_impl
6849
        res = waitid(idtype, id, &si, options);
inline
              
waitid will not be inlined into os_waitid_impl because its definition is unavailable 
os_waitid_impl
6850
        Py_END_ALLOW_THREADS
inline
        
PyEval_RestoreThread will not be inlined into os_waitid_impl because its definition is unavailable 
os_waitid_impl
6851
    } while (res < 0 && errno == EINTR && !(async_err = PyErr_CheckSignals()));
inline
                        
__errno_location will not be inlined into os_waitid_impl because its definition is unavailable 
os_waitid_impl
inline
                                                        
PyErr_CheckSignals will not be inlined into os_waitid_impl because its definition is unavailable 
os_waitid_impl
6852
    if (res < 0)
6853
        return (!async_err) ? posix_error() : NULL;
inline
                              
posix_error can be inlined into os_waitid_impl with cost=10 (threshold=375) 
os_waitid_impl
inline
                              
posix_error inlined into os_waitid_impl 
os_waitid_impl
6854

6855
    if (si.si_pid == 0)
gvn
           
load of type i32 not eliminated in favor of store because it is clobbered by call 
os_waitid_impl
gvn
           
load of type i32 not eliminated in favor of store because it is clobbered by call 
os_waitid
6856
        Py_RETURN_NONE;
gvn
        
load of type i64 not eliminated because it is clobbered by call 
os_waitid_impl
gvn
        
load of type i64 not eliminated because it is clobbered by call 
os_waitid
6857

6858
    result = PyStructSequence_New(&WaitidResultType);
inline
             
PyStructSequence_New will not be inlined into os_waitid_impl because its definition is unavailable 
os_waitid_impl
6859
    if (!result)
6860
        return NULL;
6861

6862
    PyStructSequence_SET_ITEM(result, 0, PyLong_FromPid(si.si_pid));
inline
    
PyLong_FromLong will not be inlined into os_waitid_impl because its definition is unavailable 
os_waitid_impl
gvn
    
load of type i32 not eliminated because it is clobbered by call 
os_waitid_impl
gvn
    
load of type i32 not eliminated because it is clobbered by call 
os_waitid
6863
    PyStructSequence_SET_ITEM(result, 1, _PyLong_FromUid(si.si_uid));
inline
    
_PyLong_FromUid can be inlined into os_waitid_impl with cost=45 (threshold=250) 
os_waitid_impl
inline
    
_PyLong_FromUid inlined into os_waitid_impl 
os_waitid_impl
gvn
    
load of type i32 not eliminated because it is clobbered by call 
os_waitid_impl
gvn
    
load of type i32 not eliminated because it is clobbered by call 
os_waitid
6864
    PyStructSequence_SET_ITEM(result, 2, PyLong_FromLong((long)(si.si_signo)));
inline
    
PyLong_FromLong will not be inlined into os_waitid_impl because its definition is unavailable 
os_waitid_impl
gvn
    
load of type i32 not eliminated because it is clobbered by call 
os_waitid_impl
gvn
    
load of type i32 not eliminated because it is clobbered by call 
os_waitid
6865
    PyStructSequence_SET_ITEM(result, 3, PyLong_FromLong((long)(si.si_status)));
inline
    
PyLong_FromLong will not be inlined into os_waitid_impl because its definition is unavailable 
os_waitid_impl
gvn
    
load of type i32 not eliminated because it is clobbered by call 
os_waitid_impl
gvn
    
load of type i32 not eliminated because it is clobbered by call 
os_waitid
6866
    PyStructSequence_SET_ITEM(result, 4, PyLong_FromLong((long)(si.si_code)));
inline
    
PyLong_FromLong will not be inlined into os_waitid_impl because its definition is unavailable 
os_waitid_impl
gvn
    
load of type i32 not eliminated because it is clobbered by call 
os_waitid_impl
gvn
    
load of type i32 not eliminated because it is clobbered by call 
os_waitid
6867
    if (PyErr_Occurred()) {
inline
        
PyErr_Occurred will not be inlined into os_waitid_impl because its definition is unavailable 
os_waitid_impl
6868
        Py_DECREF(result);
gvn
        
load of type i64 not eliminated because it is clobbered by call 
os_waitid_impl
gvn
        
load of type i64 not eliminated because it is clobbered by call 
os_waitid
6869
        return NULL;
6870
    }
6871

6872
    return result;
6873
}
6874
#endif /* defined(HAVE_WAITID) && !defined(__APPLE__) */
6875

6876

6877
#if defined(HAVE_WAITPID)
6878
/*[clinic input]
6879
os.waitpid
6880
    pid: pid_t
6881
    options: int
6882
    /
6883

6884
Wait for completion of a given child process.
6885

6886
Returns a tuple of information regarding the child process:
6887
    (pid, status)
6888

6889
The options argument is ignored on Windows.
6890
[clinic start generated code]*/
6891

6892
static PyObject *
6893
os_waitpid_impl(PyObject *module, pid_t pid, int options)
6894
/*[clinic end generated code: output=5c37c06887a20270 input=0bf1666b8758fda3]*/
6895
{
6896
    pid_t res;
6897
    int async_err = 0;
6898
    WAIT_TYPE status;
6899
    WAIT_STATUS_INT(status) = 0;
6900

6901
    do {
loop-vectorize
    
loop not vectorized: loop control flow is not understood by vectorizer 
os_waitpid
loop-vectorize
    
loop not vectorized 
os_waitpid
6902
        Py_BEGIN_ALLOW_THREADS
inline
        
PyEval_SaveThread will not be inlined into os_waitpid_impl because its definition is unavailable 
os_waitpid_impl
6903
        res = waitpid(pid, &status, options);
inline
              
waitpid will not be inlined into os_waitpid_impl because its definition is unavailable 
os_waitpid_impl
6904
        Py_END_ALLOW_THREADS
inline
        
PyEval_RestoreThread will not be inlined into os_waitpid_impl because its definition is unavailable 
os_waitpid_impl
6905
    } while (res < 0 && errno == EINTR && !(async_err = PyErr_CheckSignals()));
inline
                        
__errno_location will not be inlined into os_waitpid_impl because its definition is unavailable 
os_waitpid_impl
inline
                                                        
PyErr_CheckSignals will not be inlined into os_waitpid_impl because its definition is unavailable 
os_waitpid_impl
6906
    if (res < 0)
6907
        return (!async_err) ? posix_error() : NULL;
inline
                              
posix_error can be inlined into os_waitpid_impl with cost=10 (threshold=375) 
os_waitpid_impl
inline
                              
posix_error inlined into os_waitpid_impl 
os_waitpid_impl
6908

6909
    return Py_BuildValue("Ni", PyLong_FromPid(res), WAIT_STATUS_INT(status));
inline
                               
PyLong_FromLong will not be inlined into os_waitpid_impl because its definition is unavailable 
os_waitpid_impl
inline
           
_Py_BuildValue_SizeT will not be inlined into os_waitpid_impl because its definition is unavailable 
os_waitpid_impl
gvn
                                                    
load of type i32 not eliminated in favor of store because it is clobbered by call 
os_waitpid_impl
gvn
                                                    
load of type i32 not eliminated in favor of store because it is clobbered by call 
os_waitpid
6910
}
6911
#elif defined(HAVE_CWAIT)
6912
/* MS C has a variant of waitpid() that's usable for most purposes. */
6913
/*[clinic input]
6914
os.waitpid
6915
    pid: intptr_t
6916
    options: int
6917
    /
6918

6919
Wait for completion of a given process.
6920

6921
Returns a tuple of information regarding the process:
6922
    (pid, status << 8)
6923

6924
The options argument is ignored on Windows.
6925
[clinic start generated code]*/
6926

6927
static PyObject *
6928
os_waitpid_impl(PyObject *module, intptr_t pid, int options)
6929
/*[clinic end generated code: output=be836b221271d538 input=40f2440c515410f8]*/
6930
{
6931
    int status;
6932
    intptr_t res;
6933
    int async_err = 0;
6934

6935
    do {
6936
        Py_BEGIN_ALLOW_THREADS
6937
        _Py_BEGIN_SUPPRESS_IPH
6938
        res = _cwait(&status, pid, options);
6939
        _Py_END_SUPPRESS_IPH
6940
        Py_END_ALLOW_THREADS
6941
    } while (res < 0 && errno == EINTR && !(async_err = PyErr_CheckSignals()));
6942
    if (res < 0)
6943
        return (!async_err) ? posix_error() : NULL;
6944

6945
    /* shift the status left a byte so this is more like the POSIX waitpid */
6946
    return Py_BuildValue(_Py_PARSE_INTPTR "i", res, status << 8);
6947
}
6948
#endif
6949

6950

6951
#ifdef HAVE_WAIT
6952
/*[clinic input]
6953
os.wait
6954

6955
Wait for completion of a child process.
6956

6957
Returns a tuple of information about the child process:
6958
    (pid, status)
6959
[clinic start generated code]*/
6960

6961
static PyObject *
6962
os_wait_impl(PyObject *module)
6963
/*[clinic end generated code: output=6bc419ac32fb364b input=03b0182d4a4700ce]*/
6964
{
6965
    pid_t pid;
6966
    int async_err = 0;
6967
    WAIT_TYPE status;
6968
    WAIT_STATUS_INT(status) = 0;
6969

6970
    do {
loop-vectorize
    
loop not vectorized: loop control flow is not understood by vectorizer 
os_wait
loop-vectorize
    
loop not vectorized 
os_wait
6971
        Py_BEGIN_ALLOW_THREADS
inline
        
PyEval_SaveThread will not be inlined into os_wait_impl because its definition is unavailable 
os_wait_impl
6972
        pid = wait(&status);
inline
              
wait will not be inlined into os_wait_impl because its definition is unavailable 
os_wait_impl
licm
                   
hosting bitcast 
os_wait_impl
6973
        Py_END_ALLOW_THREADS
inline
        
PyEval_RestoreThread will not be inlined into os_wait_impl because its definition is unavailable 
os_wait_impl
6974
    } while (pid < 0 && errno == EINTR && !(async_err = PyErr_CheckSignals()));
inline
                        
__errno_location will not be inlined into os_wait_impl because its definition is unavailable 
os_wait_impl
inline
                                                        
PyErr_CheckSignals will not be inlined into os_wait_impl because its definition is unavailable 
os_wait_impl
6975
    if (pid < 0)
6976
        return (!async_err) ? posix_error() : NULL;
inline
                              
posix_error can be inlined into os_wait_impl with cost=10 (threshold=375) 
os_wait_impl
inline
                              
posix_error inlined into os_wait_impl 
os_wait_impl
6977

6978
    return Py_BuildValue("Ni", PyLong_FromPid(pid), WAIT_STATUS_INT(status));
inline
                               
PyLong_FromLong will not be inlined into os_wait_impl because its definition is unavailable 
os_wait_impl
inline
           
_Py_BuildValue_SizeT will not be inlined into os_wait_impl because its definition is unavailable 
os_wait_impl
gvn
                                                    
load of type i32 not eliminated in favor of store because it is clobbered by call 
os_wait_impl
gvn
                                                    
load of type i32 not eliminated in favor of store because it is clobbered by call 
os_wait
6979
}
6980
#endif /* HAVE_WAIT */
6981

6982

6983
#if defined(HAVE_READLINK) || defined(MS_WINDOWS)
6984
PyDoc_STRVAR(readlink__doc__,
6985
"readlink(path, *, dir_fd=None) -> path\n\n\
6986
Return a string representing the path to which the symbolic link points.\n\
6987
\n\
6988
If dir_fd is not None, it should be a file descriptor open to a directory,\n\
6989
  and path should be relative; path will then be relative to that directory.\n\
6990
dir_fd may not be implemented on your platform.\n\
6991
  If it is unavailable, using it will raise a NotImplementedError.");
6992
#endif
6993

6994
#ifdef HAVE_READLINK
6995

6996
/* AC 3.5: merge win32 and not together */
6997
static PyObject *
6998
posix_readlink(PyObject *self, PyObject *args, PyObject *kwargs)
6999
{
7000
    path_t path;
7001
    int dir_fd = DEFAULT_DIR_FD;
7002
    char buffer[MAXPATHLEN+1];
7003
    ssize_t length;
7004
    PyObject *return_value = NULL;
7005
    static char *keywords[] = {"path", "dir_fd", NULL};
7006

7007
    memset(&path, 0, sizeof(path));
7008
    path.function_name = "readlink";
7009
    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&|$O&:readlink", keywords,
inline
         
_PyArg_ParseTupleAndKeywords_SizeT will not be inlined into posix_readlink because its definition is unavailable 
posix_readlink
7010
                          path_converter, &path,
7011
                          READLINKAT_DIR_FD_CONVERTER, &dir_fd))
7012
        return NULL;
7013

7014
    Py_BEGIN_ALLOW_THREADS
inline
    
PyEval_SaveThread will not be inlined into posix_readlink because its definition is unavailable 
posix_readlink
7015
#ifdef HAVE_READLINKAT
7016
    if (dir_fd != DEFAULT_DIR_FD)
gvn
        
load of type i32 not eliminated in favor of store because it is clobbered by call 
posix_readlink
7017
        length = readlinkat(dir_fd, path.narrow, buffer, MAXPATHLEN);
inline
                 
readlinkat will not be inlined into posix_readlink because its definition is unavailable 
posix_readlink
gvn
                                         
load of type i8* not eliminated because it is clobbered by call 
posix_readlink
7018
    else
7019
#endif
7020
        length = readlink(path.narrow, buffer, MAXPATHLEN);
inline
                 
readlink will not be inlined into posix_readlink because its definition is unavailable 
posix_readlink
7021
    Py_END_ALLOW_THREADS
inline
    
PyEval_RestoreThread will not be inlined into posix_readlink because its definition is unavailable 
posix_readlink
7022

7023
    if (length < 0) {
7024
        return_value = path_error(&path);
inline
                       
path_error can be inlined into posix_readlink with cost=10 (threshold=375) 
posix_readlink
inline
                       
path_error inlined into posix_readlink 
posix_readlink
7025
        goto exit;
7026
    }
7027
    buffer[length] = '\0';
7028

7029
    if (PyUnicode_Check(path.object))
gvn
        
load of type %struct._object* not eliminated because it is clobbered by call 
posix_readlink
7030
        return_value = PyUnicode_DecodeFSDefaultAndSize(buffer, length);
inline
                       
PyUnicode_DecodeFSDefaultAndSize will not be inlined into posix_readlink because its definition is unavailable 
posix_readlink
7031
    else
7032
        return_value = PyBytes_FromStringAndSize(buffer, length);
inline
                       
PyBytes_FromStringAndSize will not be inlined into posix_readlink because its definition is unavailable 
posix_readlink
7033
exit:
7034
    path_cleanup(&path);
inline
    
path_cleanup can be inlined into posix_readlink with cost=20 (threshold=250) 
posix_readlink
inline
    
path_cleanup inlined into posix_readlink 
posix_readlink
7035
    return return_value;
7036
}
7037

7038
#endif /* HAVE_READLINK */
7039

7040
#if !defined(HAVE_READLINK) && defined(MS_WINDOWS)
7041

7042
static PyObject *
7043
win_readlink(PyObject *self, PyObject *args, PyObject *kwargs)
7044
{
7045
    const wchar_t *path;
7046
    DWORD n_bytes_returned;
7047
    DWORD io_result;
7048
    PyObject *po, *result;
7049
    int dir_fd;
7050
    HANDLE reparse_point_handle;
7051

7052
    char target_buffer[_Py_MAXIMUM_REPARSE_DATA_BUFFER_SIZE];
7053
    _Py_REPARSE_DATA_BUFFER *rdb = (_Py_REPARSE_DATA_BUFFER *)target_buffer;
7054
    const wchar_t *print_name;
7055

7056
    static char *keywords[] = {"path", "dir_fd", NULL};
7057

7058
    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "U|$O&:readlink", keywords,
7059
                          &po,
7060
                          dir_fd_unavailable, &dir_fd
7061
                          ))
7062
        return NULL;
7063

7064
    path = PyUnicode_AsUnicode(po);
7065
    if (path == NULL)
7066
        return NULL;
7067

7068
    /* First get a handle to the reparse point */
7069
    Py_BEGIN_ALLOW_THREADS
7070
    reparse_point_handle = CreateFileW(
7071
        path,
7072
        0,
7073
        0,
7074
        0,
7075
        OPEN_EXISTING,
7076
        FILE_FLAG_OPEN_REPARSE_POINT|FILE_FLAG_BACKUP_SEMANTICS,
7077
        0);
7078
    Py_END_ALLOW_THREADS
7079

7080
    if (reparse_point_handle==INVALID_HANDLE_VALUE)
7081
        return win32_error_object("readlink", po);
7082

7083
    Py_BEGIN_ALLOW_THREADS
7084
    /* New call DeviceIoControl to read the reparse point */
7085
    io_result = DeviceIoControl(
7086
        reparse_point_handle,
7087
        FSCTL_GET_REPARSE_POINT,
7088
        0, 0, /* in buffer */
7089
        target_buffer, sizeof(target_buffer),
7090
        &n_bytes_returned,
7091
        0 /* we're not using OVERLAPPED_IO */
7092
        );
7093
    CloseHandle(reparse_point_handle);
7094
    Py_END_ALLOW_THREADS
7095

7096
    if (io_result==0)
7097
        return win32_error_object("readlink", po);
7098

7099
    if (rdb->ReparseTag != IO_REPARSE_TAG_SYMLINK)
7100
    {
7101
        PyErr_SetString(PyExc_ValueError,
7102
                "not a symbolic link");
7103
        return NULL;
7104
    }
7105
    print_name = rdb->SymbolicLinkReparseBuffer.PathBuffer +
7106
                 rdb->SymbolicLinkReparseBuffer.PrintNameOffset;
7107

7108
    result = PyUnicode_FromWideChar(print_name,
7109
                    rdb->SymbolicLinkReparseBuffer.PrintNameLength/2);
7110
    return result;
7111
}
7112

7113
#endif /* !defined(HAVE_READLINK) && defined(MS_WINDOWS) */
7114

7115

7116

7117
#ifdef HAVE_SYMLINK
7118

7119
#if defined(MS_WINDOWS)
7120

7121
/* Grab CreateSymbolicLinkW dynamically from kernel32 */
7122
static DWORD (CALLBACK *Py_CreateSymbolicLinkW)(LPCWSTR, LPCWSTR, DWORD) = NULL;
7123

7124
static int
7125
check_CreateSymbolicLink(void)
7126
{
7127
    HINSTANCE hKernel32;
7128
    /* only recheck */
7129
    if (Py_CreateSymbolicLinkW)
7130
        return 1;
7131
    hKernel32 = GetModuleHandleW(L"KERNEL32");
7132
    *(FARPROC*)&Py_CreateSymbolicLinkW = GetProcAddress(hKernel32,
7133
                                                        "CreateSymbolicLinkW");
7134
    return Py_CreateSymbolicLinkW != NULL;
7135
}
7136

7137
/* Remove the last portion of the path */
7138
static void
7139
_dirnameW(WCHAR *path)
7140
{
7141
    WCHAR *ptr;
7142

7143
    /* walk the path from the end until a backslash is encountered */
7144
    for(ptr = path + wcslen(path); ptr != path; ptr--) {
7145
        if (*ptr == L'\\' || *ptr == L'/')
7146
            break;
7147
    }
7148
    *ptr = 0;
7149
}
7150

7151
/* Is this path absolute? */
7152
static int
7153
_is_absW(const WCHAR *path)
7154
{
7155
    return path[0] == L'\\' || path[0] == L'/' || path[1] == L':';
7156

7157
}
7158

7159
/* join root and rest with a backslash */
7160
static void
7161
_joinW(WCHAR *dest_path, const WCHAR *root, const WCHAR *rest)
7162
{
7163
    size_t root_len;
7164

7165
    if (_is_absW(rest)) {
7166
        wcscpy(dest_path, rest);
7167
        return;
7168
    }
7169

7170
    root_len = wcslen(root);
7171

7172
    wcscpy(dest_path, root);
7173
    if(root_len) {
7174
        dest_path[root_len] = L'\\';
7175
        root_len++;
7176
    }
7177
    wcscpy(dest_path+root_len, rest);
7178
}
7179

7180
/* Return True if the path at src relative to dest is a directory */
7181
static int
7182
_check_dirW(LPCWSTR src, LPCWSTR dest)
7183
{
7184
    WIN32_FILE_ATTRIBUTE_DATA src_info;
7185
    WCHAR dest_parent[MAX_PATH];
7186
    WCHAR src_resolved[MAX_PATH] = L"";
7187

7188
    /* dest_parent = os.path.dirname(dest) */
7189
    wcscpy(dest_parent, dest);
7190
    _dirnameW(dest_parent);
7191
    /* src_resolved = os.path.join(dest_parent, src) */
7192
    _joinW(src_resolved, dest_parent, src);
7193
    return (
7194
        GetFileAttributesExW(src_resolved, GetFileExInfoStandard, &src_info)
7195
        && src_info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY
7196
    );
7197
}
7198
#endif
7199

7200

7201
/*[clinic input]
7202
os.symlink
7203
    src: path_t
7204
    dst: path_t
7205
    target_is_directory: bool = False
7206
    *
7207
    dir_fd: dir_fd(requires='symlinkat')=None
7208

7209
# "symlink(src, dst, target_is_directory=False, *, dir_fd=None)\n\n\
7210

7211
Create a symbolic link pointing to src named dst.
7212

7213
target_is_directory is required on Windows if the target is to be
7214
  interpreted as a directory.  (On Windows, symlink requires
7215
  Windows 6.0 or greater, and raises a NotImplementedError otherwise.)
7216
  target_is_directory is ignored on non-Windows platforms.
7217

7218
If dir_fd is not None, it should be a file descriptor open to a directory,
7219
  and path should be relative; path will then be relative to that directory.
7220
dir_fd may not be implemented on your platform.
7221
  If it is unavailable, using it will raise a NotImplementedError.
7222

7223
[clinic start generated code]*/
7224

7225
static PyObject *
7226
os_symlink_impl(PyObject *module, path_t *src, path_t *dst,
7227
                int target_is_directory, int dir_fd)
7228
/*[clinic end generated code: output=08ca9f3f3cf960f6 input=e820ec4472547bc3]*/
7229
{
7230
#ifdef MS_WINDOWS
7231
    DWORD result;
7232
#else
7233
    int result;
7234
#endif
7235

7236
#ifdef MS_WINDOWS
7237
    if (!check_CreateSymbolicLink()) {
7238
        PyErr_SetString(PyExc_NotImplementedError,
7239
            "CreateSymbolicLink functions not found");
7240
        return NULL;
7241
        }
7242
    if (!win32_can_symlink) {
7243
        PyErr_SetString(PyExc_OSError, "symbolic link privilege not held");
7244
        return NULL;
7245
        }
7246
#endif
7247

7248
    if ((src->narrow && dst->wide) || (src->wide && dst->narrow)) {
gvn
              
load of type i8* not eliminated because it is clobbered by call 
os_symlink
gvn
                             
load of type i32* not eliminated because it is clobbered by call 
os_symlink
gvn
                                            
load of type i32* not eliminated because it is clobbered by call 
os_symlink
gvn
                                                         
load of type i8* not eliminated because it is clobbered by call 
os_symlink
7249
        PyErr_SetString(PyExc_ValueError,
inline
        
PyErr_SetString will not be inlined into os_symlink_impl because its definition is unavailable 
os_symlink_impl
gvn
                        
load of type %struct._object* not eliminated because it is clobbered by call 
os_symlink
7250
            "symlink: src and dst must be the same type");
7251
        return NULL;
7252
    }
7253

7254
#ifdef MS_WINDOWS
7255

7256
    Py_BEGIN_ALLOW_THREADS
7257
    /* if src is a directory, ensure target_is_directory==1 */
7258
    target_is_directory |= _check_dirW(src->wide, dst->wide);
7259
    result = Py_CreateSymbolicLinkW(dst->wide, src->wide,
7260
                                    target_is_directory);
7261
    Py_END_ALLOW_THREADS
7262

7263
    if (!result)
7264
        return path_error2(src, dst);
7265

7266
#else
7267

7268
    Py_BEGIN_ALLOW_THREADS
inline
    
PyEval_SaveThread will not be inlined into os_symlink_impl because its definition is unavailable 
os_symlink_impl
7269
#if HAVE_SYMLINKAT
7270
    if (dir_fd != DEFAULT_DIR_FD)
7271
        result = symlinkat(src->narrow, dir_fd, dst->narrow);
inline
                 
symlinkat will not be inlined into os_symlink_impl because its definition is unavailable 
os_symlink_impl
gvn
                                                     
load of type i8* not eliminated because it is clobbered by call 
os_symlink_impl
gvn
                                                     
load of type i8* not eliminated in favor of load because it is clobbered by call 
os_symlink
7272
    else
7273
#endif
7274
        result = symlink(src->narrow, dst->narrow);
inline
                 
symlink will not be inlined into os_symlink_impl because its definition is unavailable 
os_symlink_impl
7275
    Py_END_ALLOW_THREADS
inline
    
PyEval_RestoreThread will not be inlined into os_symlink_impl because its definition is unavailable 
os_symlink_impl
7276

7277
    if (result)
7278
        return path_error2(src, dst);
inline
               
path_error2 can be inlined into os_symlink_impl with cost=-14990 (threshold=375) 
os_symlink_impl
inline
               
path_error2 inlined into os_symlink_impl 
os_symlink_impl
7279
#endif
7280

7281
    Py_RETURN_NONE;
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_symlink_impl
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_symlink
7282
}
7283
#endif /* HAVE_SYMLINK */
7284

7285

7286

7287

7288
static PyStructSequence_Field times_result_fields[] = {
7289
    {"user",    "user time"},
7290
    {"system",   "system time"},
7291
    {"children_user",    "user time of children"},
7292
    {"children_system",    "system time of children"},
7293
    {"elapsed",    "elapsed time since an arbitrary point in the past"},
7294
    {NULL}
7295
};
7296

7297
PyDoc_STRVAR(times_result__doc__,
7298
"times_result: Result from os.times().\n\n\
7299
This object may be accessed either as a tuple of\n\
7300
  (user, system, children_user, children_system, elapsed),\n\
7301
or via the attributes user, system, children_user, children_system,\n\
7302
and elapsed.\n\
7303
\n\
7304
See os.times for more information.");
7305

7306
static PyStructSequence_Desc times_result_desc = {
7307
    "times_result", /* name */
7308
    times_result__doc__, /* doc */
7309
    times_result_fields,
7310
    5
7311
};
7312

7313
static PyTypeObject TimesResultType;
7314

7315
#ifdef MS_WINDOWS
7316
#define HAVE_TIMES  /* mandatory, for the method table */
7317
#endif
7318

7319
#ifdef HAVE_TIMES
7320

7321
static PyObject *
7322
build_times_result(double user, double system,
7323
    double children_user, double children_system,
7324
    double elapsed)
7325
{
7326
    PyObject *value = PyStructSequence_New(&TimesResultType);
inline
                      
PyStructSequence_New will not be inlined into build_times_result because its definition is unavailable 
build_times_result
7327
    if (value == NULL)
7328
        return NULL;
7329

7330
#define SET(i, field) \
7331
    { \
7332
    PyObject *o = PyFloat_FromDouble(field); \
7333
    if (!o) { \
7334
        Py_DECREF(value); \
7335
        return NULL; \
7336
    } \
7337
    PyStructSequence_SET_ITEM(value, i, o); \
7338
    } \
7339

7340
    SET(0, user);
inline
    
PyFloat_FromDouble will not be inlined into build_times_result because its definition is unavailable 
build_times_result
gvn
    
load of type i64 not eliminated because it is clobbered by call 
build_times_result
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_times_impl
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_times
7341
    SET(1, system);
inline
    
PyFloat_FromDouble will not be inlined into build_times_result because its definition is unavailable 
build_times_result
gvn
    
load of type i64 not eliminated because it is clobbered by call 
build_times_result
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_times_impl
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_times
7342
    SET(2, children_user);
inline
    
PyFloat_FromDouble will not be inlined into build_times_result because its definition is unavailable 
build_times_result
gvn
    
load of type i64 not eliminated because it is clobbered by call 
build_times_result
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_times_impl
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_times
7343
    SET(3, children_system);
inline
    
PyFloat_FromDouble will not be inlined into build_times_result because its definition is unavailable 
build_times_result
gvn
    
load of type i64 not eliminated because it is clobbered by call 
build_times_result
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_times_impl
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_times
7344
    SET(4, elapsed);
inline
    
PyFloat_FromDouble will not be inlined into build_times_result because its definition is unavailable 
build_times_result
gvn
    
load of type i64 not eliminated because it is clobbered by call 
build_times_result
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_times_impl
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_times
7345

7346
#undef SET
7347

7348
    return value;
7349
}
7350

7351

7352
#ifndef MS_WINDOWS
7353
#define NEED_TICKS_PER_SECOND
7354
static long ticks_per_second = -1;
7355
#endif /* MS_WINDOWS */
7356

7357
/*[clinic input]
7358
os.times
7359

7360
Return a collection containing process timing information.
7361

7362
The object returned behaves like a named tuple with these fields:
7363
  (utime, stime, cutime, cstime, elapsed_time)
7364
All fields are floating point numbers.
7365
[clinic start generated code]*/
7366

7367
static PyObject *
7368
os_times_impl(PyObject *module)
7369
/*[clinic end generated code: output=35f640503557d32a input=2bf9df3d6ab2e48b]*/
7370
#ifdef MS_WINDOWS
7371
{
7372
    FILETIME create, exit, kernel, user;
7373
    HANDLE hProc;
7374
    hProc = GetCurrentProcess();
7375
    GetProcessTimes(hProc, &create, &exit, &kernel, &user);
7376
    /* The fields of a FILETIME structure are the hi and lo part
7377
       of a 64-bit value expressed in 100 nanosecond units.
7378
       1e7 is one second in such units; 1e-7 the inverse.
7379
       429.4967296 is 2**32 / 1e7 or 2**32 * 1e-7.
7380
    */
7381
    return build_times_result(
7382
        (double)(user.dwHighDateTime*429.4967296 +
7383
                 user.dwLowDateTime*1e-7),
7384
        (double)(kernel.dwHighDateTime*429.4967296 +
7385
                 kernel.dwLowDateTime*1e-7),
7386
        (double)0,
7387
        (double)0,
7388
        (double)0);
7389
}
7390
#else /* MS_WINDOWS */
7391
{
7392

7393

7394
    struct tms t;
7395
    clock_t c;
7396
    errno = 0;
inline
    
__errno_location will not be inlined into os_times_impl because its definition is unavailable 
os_times_impl
7397
    c = times(&t);
inline
        
times will not be inlined into os_times_impl because its definition is unavailable 
os_times_impl
7398
    if (c == (clock_t) -1)
7399
        return posix_error();
inline
               
posix_error can be inlined into os_times_impl with cost=10 (threshold=375) 
os_times_impl
inline
               
posix_error inlined into os_times_impl 
os_times_impl
7400
    return build_times_result(
inline
           
build_times_result can be inlined into os_times_impl with cost=-14535 (threshold=250) 
os_times_impl
inline
           
build_times_result inlined into os_times_impl 
os_times_impl
7401
                         (double)t.tms_utime / ticks_per_second,
gvn
                                   
load of type i64 not eliminated because it is clobbered by call 
os_times_impl
gvn
                                               
load of type i64 not eliminated because it is clobbered by call 
os_times_impl
gvn
                                   
load of type i64 not eliminated because it is clobbered by call 
os_times
gvn
                                               
load of type i64 not eliminated because it is clobbered by call 
os_times
7402
                         (double)t.tms_stime / ticks_per_second,
gvn
                                   
load of type i64 not eliminated because it is clobbered by call 
os_times_impl
gvn
                                   
load of type i64 not eliminated because it is clobbered by call 
os_times
7403
                         (double)t.tms_cutime / ticks_per_second,
gvn
                                   
load of type i64 not eliminated because it is clobbered by call 
os_times_impl
gvn
                                   
load of type i64 not eliminated because it is clobbered by call 
os_times
7404
                         (double)t.tms_cstime / ticks_per_second,
gvn
                                   
load of type i64 not eliminated because it is clobbered by call 
os_times_impl
gvn
                                   
load of type i64 not eliminated because it is clobbered by call 
os_times
7405
                         (double)c / ticks_per_second);
7406
}
7407
#endif /* MS_WINDOWS */
7408
#endif /* HAVE_TIMES */
7409

7410

7411
#ifdef HAVE_GETSID
7412
/*[clinic input]
7413
os.getsid
7414

7415
    pid: pid_t
7416
    /
7417

7418
Call the system call getsid(pid) and return the result.
7419
[clinic start generated code]*/
7420

7421
static PyObject *
7422
os_getsid_impl(PyObject *module, pid_t pid)
7423
/*[clinic end generated code: output=112deae56b306460 input=eeb2b923a30ce04e]*/
7424
{
7425
    int sid;
7426
    sid = getsid(pid);
inline
          
getsid will not be inlined into os_getsid_impl because its definition is unavailable 
os_getsid_impl
7427
    if (sid < 0)
7428
        return posix_error();
inline
               
posix_error can be inlined into os_getsid_impl with cost=10 (threshold=375) 
os_getsid_impl
inline
               
posix_error inlined into os_getsid_impl 
os_getsid_impl
7429
    return PyLong_FromLong((long)sid);
inline
           
PyLong_FromLong will not be inlined into os_getsid_impl because its definition is unavailable 
os_getsid_impl
7430
}
7431
#endif /* HAVE_GETSID */
7432

7433

7434
#ifdef HAVE_SETSID
7435
/*[clinic input]
7436
os.setsid
7437

7438
Call the system call setsid().
7439
[clinic start generated code]*/
7440

7441
static PyObject *
7442
os_setsid_impl(PyObject *module)
7443
/*[clinic end generated code: output=e2ddedd517086d77 input=5fff45858e2f0776]*/
7444
{
7445
    if (setsid() < 0)
inline
        
setsid will not be inlined into os_setsid_impl because its definition is unavailable 
os_setsid_impl
7446
        return posix_error();
inline
               
posix_error can be inlined into os_setsid_impl with cost=10 (threshold=375) 
os_setsid_impl
inline
               
posix_error inlined into os_setsid_impl 
os_setsid_impl
7447
    Py_RETURN_NONE;
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_setsid_impl
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_setsid
7448
}
7449
#endif /* HAVE_SETSID */
7450

7451

7452
#ifdef HAVE_SETPGID
7453
/*[clinic input]
7454
os.setpgid
7455

7456
    pid: pid_t
7457
    pgrp: pid_t
7458
    /
7459

7460
Call the system call setpgid(pid, pgrp).
7461
[clinic start generated code]*/
7462

7463
static PyObject *
7464
os_setpgid_impl(PyObject *module, pid_t pid, pid_t pgrp)
7465
/*[clinic end generated code: output=6461160319a43d6a input=fceb395eca572e1a]*/
7466
{
7467
    if (setpgid(pid, pgrp) < 0)
inline
        
setpgid will not be inlined into os_setpgid_impl because its definition is unavailable 
os_setpgid_impl
7468
        return posix_error();
inline
               
posix_error can be inlined into os_setpgid_impl with cost=10 (threshold=375) 
os_setpgid_impl
inline
               
posix_error inlined into os_setpgid_impl 
os_setpgid_impl
7469
    Py_RETURN_NONE;
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_setpgid_impl
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_setpgid
7470
}
7471
#endif /* HAVE_SETPGID */
7472

7473

7474
#ifdef HAVE_TCGETPGRP
7475
/*[clinic input]
7476
os.tcgetpgrp
7477

7478
    fd: int
7479
    /
7480

7481
Return the process group associated with the terminal specified by fd.
7482
[clinic start generated code]*/
7483

7484
static PyObject *
7485
os_tcgetpgrp_impl(PyObject *module, int fd)
7486
/*[clinic end generated code: output=f865e88be86c272b input=7f6c18eac10ada86]*/
7487
{
7488
    pid_t pgid = tcgetpgrp(fd);
inline
                 
tcgetpgrp will not be inlined into os_tcgetpgrp_impl because its definition is unavailable 
os_tcgetpgrp_impl
7489
    if (pgid < 0)
7490
        return posix_error();
inline
               
posix_error can be inlined into os_tcgetpgrp_impl with cost=10 (threshold=375) 
os_tcgetpgrp_impl
inline
               
posix_error inlined into os_tcgetpgrp_impl 
os_tcgetpgrp_impl
7491
    return PyLong_FromPid(pgid);
inline
           
PyLong_FromLong will not be inlined into os_tcgetpgrp_impl because its definition is unavailable 
os_tcgetpgrp_impl
7492
}
7493
#endif /* HAVE_TCGETPGRP */
7494

7495

7496
#ifdef HAVE_TCSETPGRP
7497
/*[clinic input]
7498
os.tcsetpgrp
7499

7500
    fd: int
7501
    pgid: pid_t
7502
    /
7503

7504
Set the process group associated with the terminal specified by fd.
7505
[clinic start generated code]*/
7506

7507
static PyObject *
7508
os_tcsetpgrp_impl(PyObject *module, int fd, pid_t pgid)
7509
/*[clinic end generated code: output=f1821a381b9daa39 input=5bdc997c6a619020]*/
7510
{
7511
    if (tcsetpgrp(fd, pgid) < 0)
inline
        
tcsetpgrp will not be inlined into os_tcsetpgrp_impl because its definition is unavailable 
os_tcsetpgrp_impl
7512
        return posix_error();
inline
               
posix_error can be inlined into os_tcsetpgrp_impl with cost=10 (threshold=375) 
os_tcsetpgrp_impl
inline
               
posix_error inlined into os_tcsetpgrp_impl 
os_tcsetpgrp_impl
7513
    Py_RETURN_NONE;
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_tcsetpgrp_impl
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_tcsetpgrp
7514
}
7515
#endif /* HAVE_TCSETPGRP */
7516

7517
/* Functions acting on file descriptors */
7518

7519
#ifdef O_CLOEXEC
7520
extern int _Py_open_cloexec_works;
7521
#endif
7522

7523

7524
/*[clinic input]
7525
os.open -> int
7526
    path: path_t
7527
    flags: int
7528
    mode: int = 0o777
7529
    *
7530
    dir_fd: dir_fd(requires='openat') = None
7531

7532
# "open(path, flags, mode=0o777, *, dir_fd=None)\n\n\
7533

7534
Open a file for low level IO.  Returns a file descriptor (integer).
7535

7536
If dir_fd is not None, it should be a file descriptor open to a directory,
7537
  and path should be relative; path will then be relative to that directory.
7538
dir_fd may not be implemented on your platform.
7539
  If it is unavailable, using it will raise a NotImplementedError.
7540
[clinic start generated code]*/
7541

7542
static int
7543
os_open_impl(PyObject *module, path_t *path, int flags, int mode, int dir_fd)
7544
/*[clinic end generated code: output=abc7227888c8bc73 input=ad8623b29acd2934]*/
7545
{
7546
    int fd;
7547
    int async_err = 0;
7548

7549
#ifdef O_CLOEXEC
7550
    int *atomic_flag_works = &_Py_open_cloexec_works;
7551
#elif !defined(MS_WINDOWS)
7552
    int *atomic_flag_works = NULL;
7553
#endif
7554

7555
#ifdef MS_WINDOWS
7556
    flags |= O_NOINHERIT;
7557
#elif defined(O_CLOEXEC)
7558
    flags |= O_CLOEXEC;
7559
#endif
7560

7561
    _Py_BEGIN_SUPPRESS_IPH
7562
    do {
loop-vectorize
    
loop not vectorized: loop control flow is not understood by vectorizer 
os_open
loop-vectorize
    
loop not vectorized 
os_open
7563
        Py_BEGIN_ALLOW_THREADS
inline
        
PyEval_SaveThread will not be inlined into os_open_impl because its definition is unavailable 
os_open_impl
7564
#ifdef MS_WINDOWS
7565
        fd = _wopen(path->wide, flags, mode);
7566
#else
7567
#ifdef HAVE_OPENAT
7568
        if (dir_fd != DEFAULT_DIR_FD)
licm
                   
hosting icmp 
os_open_impl
7569
            fd = openat(dir_fd, path->narrow, flags, mode);
inline
                 
openat64 will not be inlined into os_open_impl because its definition is unavailable 
os_open_impl
licm
                                      
hosting getelementptr 
os_open_impl
licm
                                      
failed to move load with loop-invariant address because the loop may invalidate its value 
os_open_impl
gvn
                                      
load of type i8* not eliminated because it is clobbered by call 
os_open_impl
licm
                                      
failed to move load with loop-invariant address because the loop may invalidate its value 
os_open
gvn
                                      
load of type i8* not eliminated because it is clobbered by call 
os_open
7570
        else
7571
#endif /* HAVE_OPENAT */
7572
            fd = open(path->narrow, flags, mode);
inline
                 
open64 will not be inlined into os_open_impl because its definition is unavailable 
os_open_impl
7573
#endif /* !MS_WINDOWS */
7574
        Py_END_ALLOW_THREADS
inline
        
PyEval_RestoreThread will not be inlined into os_open_impl because its definition is unavailable 
os_open_impl
7575
    } while (fd < 0 && errno == EINTR && !(async_err = PyErr_CheckSignals()));
inline
                       
__errno_location will not be inlined into os_open_impl because its definition is unavailable 
os_open_impl
inline
                                                       
PyErr_CheckSignals will not be inlined into os_open_impl because its definition is unavailable 
os_open_impl
7576
    _Py_END_SUPPRESS_IPH
7577

7578
    if (fd < 0) {
7579
        if (!async_err)
7580
            PyErr_SetFromErrnoWithFilenameObject(PyExc_OSError, path->object);
inline
            
PyErr_SetFromErrnoWithFilenameObject will not be inlined into os_open_impl because its definition is unavailable 
os_open_impl
gvn
                                                 
load of type %struct._object* not eliminated because it is clobbered by call 
os_open_impl
gvn
                                                                      
load of type %struct._object* not eliminated because it is clobbered by call 
os_open_impl
gvn
                                                 
load of type %struct._object* not eliminated because it is clobbered by call 
os_open
gvn
                                                                      
load of type %struct._object* not eliminated because it is clobbered by call 
os_open
7581
        return -1;
7582
    }
7583

7584
#ifndef MS_WINDOWS
7585
    if (_Py_set_inheritable(fd, 0, atomic_flag_works) < 0) {
inline
        
_Py_set_inheritable will not be inlined into os_open_impl because its definition is unavailable 
os_open_impl
7586
        close(fd);
inline
        
close will not be inlined into os_open_impl because its definition is unavailable 
os_open_impl
7587
        return -1;
7588
    }
7589
#endif
7590

7591
    return fd;
7592
}
7593

7594

7595
/*[clinic input]
7596
os.close
7597

7598
    fd: int
7599

7600
Close a file descriptor.
7601
[clinic start generated code]*/
7602

7603
static PyObject *
7604
os_close_impl(PyObject *module, int fd)
7605
/*[clinic end generated code: output=2fe4e93602822c14 input=2bc42451ca5c3223]*/
7606
{
7607
    int res;
7608
    /* We do not want to retry upon EINTR: see http://lwn.net/Articles/576478/
7609
     * and http://linux.derkeiler.com/Mailing-Lists/Kernel/2005-09/3000.html
7610
     * for more details.
7611
     */
7612
    Py_BEGIN_ALLOW_THREADS
inline
    
PyEval_SaveThread will not be inlined into os_close_impl because its definition is unavailable 
os_close_impl
7613
    _Py_BEGIN_SUPPRESS_IPH
7614
    res = close(fd);
inline
          
close will not be inlined into os_close_impl because its definition is unavailable 
os_close_impl
7615
    _Py_END_SUPPRESS_IPH
7616
    Py_END_ALLOW_THREADS
inline
    
PyEval_RestoreThread will not be inlined into os_close_impl because its definition is unavailable 
os_close_impl
7617
    if (res < 0)
7618
        return posix_error();
inline
               
posix_error can be inlined into os_close_impl with cost=10 (threshold=375) 
os_close_impl
inline
               
posix_error inlined into os_close_impl 
os_close_impl
7619
    Py_RETURN_NONE;
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_close_impl
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_close
7620
}
7621

7622

7623
/*[clinic input]
7624
os.closerange
7625

7626
    fd_low: int
7627
    fd_high: int
7628
    /
7629

7630
Closes all file descriptors in [fd_low, fd_high), ignoring errors.
7631
[clinic start generated code]*/
7632

7633
static PyObject *
7634
os_closerange_impl(PyObject *module, int fd_low, int fd_high)
7635
/*[clinic end generated code: output=0ce5c20fcda681c2 input=5855a3d053ebd4ec]*/
7636
{
7637
    int i;
7638
    Py_BEGIN_ALLOW_THREADS
inline
    
PyEval_SaveThread will not be inlined into os_closerange_impl because its definition is unavailable 
os_closerange_impl
7639
    _Py_BEGIN_SUPPRESS_IPH
7640
    for (i = Py_MAX(fd_low, 0); i < fd_high; i++)
loop-vectorize
    
loop not vectorized 
os_closerange
7641
        close(i);
inline
        
close will not be inlined into os_closerange_impl because its definition is unavailable 
os_closerange_impl
loop-vectorize
        
loop not vectorized: call instruction cannot be vectorized 
os_closerange
7642
    _Py_END_SUPPRESS_IPH
7643
    Py_END_ALLOW_THREADS
inline
    
PyEval_RestoreThread will not be inlined into os_closerange_impl because its definition is unavailable 
os_closerange_impl
7644
    Py_RETURN_NONE;
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_closerange_impl
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_closerange
7645
}
7646

7647

7648
/*[clinic input]
7649
os.dup -> int
7650

7651
    fd: int
7652
    /
7653

7654
Return a duplicate of a file descriptor.
7655
[clinic start generated code]*/
7656

7657
static int
7658
os_dup_impl(PyObject *module, int fd)
7659
/*[clinic end generated code: output=486f4860636b2a9f input=6f10f7ea97f7852a]*/
7660
{
7661
    return _Py_dup(fd);
inline
           
_Py_dup will not be inlined into os_dup_impl because its definition is unavailable 
os_dup_impl
7662
}
7663

7664

7665
/*[clinic input]
7666
os.dup2
7667
    fd: int
7668
    fd2: int
7669
    inheritable: bool=True
7670

7671
Duplicate file descriptor.
7672
[clinic start generated code]*/
7673

7674
static PyObject *
7675
os_dup2_impl(PyObject *module, int fd, int fd2, int inheritable)
7676
/*[clinic end generated code: output=db832a2d872ccc5f input=76e96f511be0352f]*/
7677
{
7678
    int res;
7679
#if defined(HAVE_DUP3) && \
7680
    !(defined(HAVE_FCNTL_H) && defined(F_DUP2FD_CLOEXEC))
7681
    /* dup3() is available on Linux 2.6.27+ and glibc 2.9 */
7682
    int dup3_works = -1;
7683
#endif
7684

7685
    if (fd < 0 || fd2 < 0)
7686
        return posix_error();
inline
               
posix_error can be inlined into os_dup2_impl with cost=10 (threshold=375) 
os_dup2_impl
inline
               
posix_error inlined into os_dup2_impl 
os_dup2_impl
7687

7688
    /* dup2() can fail with EINTR if the target FD is already open, because it
7689
     * then has to be closed. See os_close_impl() for why we don't handle EINTR
7690
     * upon close(), and therefore below.
7691
     */
7692
#ifdef MS_WINDOWS
7693
    Py_BEGIN_ALLOW_THREADS
7694
    _Py_BEGIN_SUPPRESS_IPH
7695
    res = dup2(fd, fd2);
7696
    _Py_END_SUPPRESS_IPH
7697
    Py_END_ALLOW_THREADS
7698
    if (res < 0)
7699
        return posix_error();
7700

7701
    /* Character files like console cannot be make non-inheritable */
7702
    if (!inheritable && _Py_set_inheritable(fd2, 0, NULL) < 0) {
7703
        close(fd2);
7704
        return NULL;
7705
    }
7706

7707
#elif defined(HAVE_FCNTL_H) && defined(F_DUP2FD_CLOEXEC)
7708
    Py_BEGIN_ALLOW_THREADS
7709
    if (!inheritable)
7710
        res = fcntl(fd, F_DUP2FD_CLOEXEC, fd2);
7711
    else
7712
        res = dup2(fd, fd2);
7713
    Py_END_ALLOW_THREADS
7714
    if (res < 0)
7715
        return posix_error();
7716

7717
#else
7718

7719
#ifdef HAVE_DUP3
7720
    if (!inheritable && dup3_works != 0) {
7721
        Py_BEGIN_ALLOW_THREADS
inline
        
PyEval_SaveThread will not be inlined into os_dup2_impl because its definition is unavailable 
os_dup2_impl
7722
        res = dup3(fd, fd2, O_CLOEXEC);
inline
              
dup3 will not be inlined into os_dup2_impl because its definition is unavailable 
os_dup2_impl
7723
        Py_END_ALLOW_THREADS
inline
        
PyEval_RestoreThread will not be inlined into os_dup2_impl because its definition is unavailable 
os_dup2_impl
7724
        if (res < 0) {
7725
            if (dup3_works == -1)
7726
                dup3_works = (errno != ENOSYS);
inline
                              
__errno_location will not be inlined into os_dup2_impl because its definition is unavailable 
os_dup2_impl
7727
            if (dup3_works)
7728
                return posix_error();
inline
                       
posix_error can be inlined into os_dup2_impl with cost=10 (threshold=375) 
os_dup2_impl
inline
                       
posix_error inlined into os_dup2_impl 
os_dup2_impl
7729
        }
7730
    }
7731

7732
    if (inheritable || dup3_works == 0)
7733
    {
7734
#endif
7735
        Py_BEGIN_ALLOW_THREADS
inline
        
PyEval_SaveThread will not be inlined into os_dup2_impl because its definition is unavailable 
os_dup2_impl
7736
        res = dup2(fd, fd2);
inline
              
dup2 will not be inlined into os_dup2_impl because its definition is unavailable 
os_dup2_impl
7737
        Py_END_ALLOW_THREADS
inline
        
PyEval_RestoreThread will not be inlined into os_dup2_impl because its definition is unavailable 
os_dup2_impl
7738
        if (res < 0)
7739
            return posix_error();
inline
                   
posix_error can be inlined into os_dup2_impl with cost=10 (threshold=375) 
os_dup2_impl
inline
                   
posix_error inlined into os_dup2_impl 
os_dup2_impl
7740

7741
        if (!inheritable && _Py_set_inheritable(fd2, 0, NULL) < 0) {
inline
                            
_Py_set_inheritable will not be inlined into os_dup2_impl because its definition is unavailable 
os_dup2_impl
7742
            close(fd2);
inline
            
close will not be inlined into os_dup2_impl because its definition is unavailable 
os_dup2_impl
7743
            return NULL;
7744
        }
7745
#ifdef HAVE_DUP3
7746
    }
7747
#endif
7748

7749
#endif
7750

7751
    Py_RETURN_NONE;
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_dup2_impl
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_dup2
7752
}
7753

7754

7755
#ifdef HAVE_LOCKF
7756
/*[clinic input]
7757
os.lockf
7758

7759
    fd: int
7760
        An open file descriptor.
7761
    command: int
7762
        One of F_LOCK, F_TLOCK, F_ULOCK or F_TEST.
7763
    length: Py_off_t
7764
        The number of bytes to lock, starting at the current position.
7765
    /
7766

7767
Apply, test or remove a POSIX lock on an open file descriptor.
7768

7769
[clinic start generated code]*/
7770

7771
static PyObject *
7772
os_lockf_impl(PyObject *module, int fd, int command, Py_off_t length)
7773
/*[clinic end generated code: output=af7051f3e7c29651 input=65da41d2106e9b79]*/
7774
{
7775
    int res;
7776

7777
    Py_BEGIN_ALLOW_THREADS
inline
    
PyEval_SaveThread will not be inlined into os_lockf_impl because its definition is unavailable 
os_lockf_impl
7778
    res = lockf(fd, command, length);
inline
          
lockf64 will not be inlined into os_lockf_impl because its definition is unavailable 
os_lockf_impl
7779
    Py_END_ALLOW_THREADS
inline
    
PyEval_RestoreThread will not be inlined into os_lockf_impl because its definition is unavailable 
os_lockf_impl
7780

7781
    if (res < 0)
7782
        return posix_error();
inline
               
posix_error can be inlined into os_lockf_impl with cost=10 (threshold=375) 
os_lockf_impl
inline
               
posix_error inlined into os_lockf_impl 
os_lockf_impl
7783

7784
    Py_RETURN_NONE;
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_lockf_impl
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_lockf
7785
}
7786
#endif /* HAVE_LOCKF */
7787

7788

7789
/*[clinic input]
7790
os.lseek -> Py_off_t
7791

7792
    fd: int
7793
    position: Py_off_t
7794
    how: int
7795
    /
7796

7797
Set the position of a file descriptor.  Return the new position.
7798

7799
Return the new cursor position in number of bytes
7800
relative to the beginning of the file.
7801
[clinic start generated code]*/
7802

7803
static Py_off_t
7804
os_lseek_impl(PyObject *module, int fd, Py_off_t position, int how)
7805
/*[clinic end generated code: output=971e1efb6b30bd2f input=902654ad3f96a6d3]*/
7806
{
7807
    Py_off_t result;
7808

7809
#ifdef SEEK_SET
7810
    /* Turn 0, 1, 2 into SEEK_{SET,CUR,END} */
7811
    switch (how) {
7812
        case 0: how = SEEK_SET; break;
7813
        case 1: how = SEEK_CUR; break;
7814
        case 2: how = SEEK_END; break;
7815
    }
7816
#endif /* SEEK_END */
7817

7818
    if (PyErr_Occurred())
inline
        
PyErr_Occurred will not be inlined into os_lseek_impl because its definition is unavailable 
os_lseek_impl
7819
        return -1;
7820

7821
    Py_BEGIN_ALLOW_THREADS
inline
    
PyEval_SaveThread will not be inlined into os_lseek_impl because its definition is unavailable 
os_lseek_impl
7822
    _Py_BEGIN_SUPPRESS_IPH
7823
#ifdef MS_WINDOWS
7824
    result = _lseeki64(fd, position, how);
7825
#else
7826
    result = lseek(fd, position, how);
inline
             
lseek64 will not be inlined into os_lseek_impl because its definition is unavailable 
os_lseek_impl
7827
#endif
7828
    _Py_END_SUPPRESS_IPH
7829
    Py_END_ALLOW_THREADS
inline
    
PyEval_RestoreThread will not be inlined into os_lseek_impl because its definition is unavailable 
os_lseek_impl
7830
    if (result < 0)
7831
        posix_error();
inline
        
posix_error can be inlined into os_lseek_impl with cost=10 (threshold=375) 
os_lseek_impl
inline
        
posix_error inlined into os_lseek_impl 
os_lseek_impl
7832

7833
    return result;
7834
}
7835

7836

7837
/*[clinic input]
7838
os.read
7839
    fd: int
7840
    length: Py_ssize_t
7841
    /
7842

7843
Read from a file descriptor.  Returns a bytes object.
7844
[clinic start generated code]*/
7845

7846
static PyObject *
7847
os_read_impl(PyObject *module, int fd, Py_ssize_t length)
7848
/*[clinic end generated code: output=dafbe9a5cddb987b input=1df2eaa27c0bf1d3]*/
7849
{
7850
    Py_ssize_t n;
7851
    PyObject *buffer;
7852

7853
    if (length < 0) {
7854
        errno = EINVAL;
inline
        
__errno_location will not be inlined into os_read_impl because its definition is unavailable 
os_read_impl
7855
        return posix_error();
inline
               
posix_error can be inlined into os_read_impl with cost=10 (threshold=375) 
os_read_impl
inline
               
posix_error inlined into os_read_impl 
os_read_impl
7856
    }
7857

7858
#ifdef MS_WINDOWS
7859
    /* On Windows, the count parameter of read() is an int */
7860
    if (length > INT_MAX)
7861
        length = INT_MAX;
7862
#endif
7863

7864
    buffer = PyBytes_FromStringAndSize((char *)NULL, length);
inline
             
PyBytes_FromStringAndSize will not be inlined into os_read_impl because its definition is unavailable 
os_read_impl
7865
    if (buffer == NULL)
7866
        return NULL;
7867

7868
    n = _Py_read(fd, PyBytes_AS_STRING(buffer), length);
inline
        
_Py_read will not be inlined into os_read_impl because its definition is unavailable 
os_read_impl
7869
    if (n == -1) {
7870
        Py_DECREF(buffer);
gvn
        
load of type %struct._object* eliminated in favor of call 
os_read_impl
gvn
        
load of type i64 not eliminated because it is clobbered by call 
os_read_impl
gvn
        
load of type i64 not eliminated because it is clobbered by call 
os_read
7871
        return NULL;
7872
    }
7873

7874
    if (n != length)
7875
        _PyBytes_Resize(&buffer, n);
inline
        
_PyBytes_Resize will not be inlined into os_read_impl because its definition is unavailable 
os_read_impl
7876

7877
    return buffer;
gvn
           
load of type %struct._object* not eliminated in favor of store because it is clobbered by call 
os_read_impl
gvn
           
load eliminated by PRE 
os_read_impl
7878
}
7879

7880
#if (defined(HAVE_SENDFILE) && (defined(__FreeBSD__) || defined(__DragonFly__) \
7881
    || defined(__APPLE__))) || defined(HAVE_READV) || defined(HAVE_WRITEV)
7882
static Py_ssize_t
7883
iov_setup(struct iovec **iov, Py_buffer **buf, PyObject *seq, int cnt, int type)
7884
{
7885
    int i, j;
7886
    Py_ssize_t blen, total = 0;
7887

7888
    *iov = PyMem_New(struct iovec, cnt);
inline
           
PyMem_Malloc will not be inlined into iov_setup because its definition is unavailable 
iov_setup
7889
    if (*iov == NULL) {
7890
        PyErr_NoMemory();
inline
        
PyErr_NoMemory will not be inlined into iov_setup because its definition is unavailable 
iov_setup
7891
        return -1;
7892
    }
7893

7894
    *buf = PyMem_New(Py_buffer, cnt);
inline
           
PyMem_Malloc will not be inlined into iov_setup because its definition is unavailable 
iov_setup
7895
    if (*buf == NULL) {
7896
        PyMem_Del(*iov);
inline
        
PyMem_Free will not be inlined into iov_setup because its definition is unavailable 
iov_setup
gvn
                  
load of type i8* not eliminated in favor of store because it is clobbered by store 
iov_setup
7897
        PyErr_NoMemory();
inline
        
PyErr_NoMemory will not be inlined into iov_setup because its definition is unavailable 
iov_setup
7898
        return -1;
7899
    }
7900

7901
    for (i = 0; i < cnt; i++) {
loop-vectorize
    
loop not vectorized: loop control flow is not understood by vectorizer 
iov_setup
loop-vectorize
    
loop not vectorized 
iov_setup
7902
        PyObject *item = PySequence_GetItem(seq, i);
inline
                         
PySequence_GetItem will not be inlined into iov_setup because its definition is unavailable 
iov_setup
7903
        if (item == NULL)
7904
            goto fail;
7905
        if (PyObject_GetBuffer(item, &(*buf)[i], type) == -1) {
inline
            
PyObject_GetBuffer will not be inlined into iov_setup because its definition is unavailable 
iov_setup
licm
                                       
failed to move load with loop-invariant address because the loop may invalidate its value 
iov_setup
gvn
                                       
load of type %struct.bufferinfo* not eliminated because it is clobbered by call 
iov_setup
7906
            Py_DECREF(item);
gvn
            
load of type i64 not eliminated because it is clobbered by call 
iov_setup
7907
            goto fail;
7908
        }
7909
        Py_DECREF(item);
gvn
        
load of type %struct._typeobject* not eliminated because it is clobbered by call 
iov_setup
7910
        (*iov)[i].iov_base = (*buf)[i].buf;
licm
                              
failed to move load with loop-invariant address because the loop may invalidate its value 
iov_setup
licm
         
failed to move load with loop-invariant address because the loop may invalidate its value 
iov_setup
gvn
                              
load of type %struct.bufferinfo* not eliminated in favor of load because it is clobbered by call 
iov_setup
gvn
         
load of type %struct.iovec* not eliminated because it is clobbered by call 
iov_setup
7911
        blen = (*buf)[i].len;
licm
                
failed to move load with loop-invariant address because the loop may invalidate its value 
iov_setup
gvn
                
load of type %struct.bufferinfo* not eliminated because it is clobbered by store 
iov_setup
7912
        (*iov)[i].iov_len = blen;
licm
         
failed to move load with loop-invariant address because the loop may invalidate its value 
iov_setup
gvn
         
load of type %struct.iovec* not eliminated in favor of load because it is clobbered by store 
iov_setup
7913
        total += blen;
7914
    }
7915
    return total;
7916

7917
fail:
7918
    PyMem_Del(*iov);
inline
    
PyMem_Free will not be inlined into iov_setup because its definition is unavailable 
iov_setup
gvn
              
load of type i8* not eliminated in favor of store because it is clobbered by call 
iov_setup
7919
    for (j = 0; j < i; j++) {
licm
                  
hosting zext 
iov_setup
loop-vectorize
    
loop not vectorized: value that could not be identified as reduction is used outside the loop 
iov_setup
loop-vectorize
    
loop not vectorized 
iov_setup
7920
        PyBuffer_Release(&(*buf)[j]);
inline
        
PyBuffer_Release will not be inlined into iov_setup because its definition is unavailable 
iov_setup
7921
    }
7922
    PyMem_Del(*buf);
inline
    
PyMem_Free will not be inlined into iov_setup because its definition is unavailable 
iov_setup
7923
    return -1;
7924
}
7925

7926
static void
7927
iov_cleanup(struct iovec *iov, Py_buffer *buf, int cnt)
7928
{
7929
    int i;
7930
    PyMem_Del(iov);
inline
    
PyMem_Free will not be inlined into iov_cleanup because its definition is unavailable 
iov_cleanup
7931
    for (i = 0; i < cnt; i++) {
licm
                  
hosting zext 
iov_cleanup
loop-vectorize
    
loop not vectorized 
os_readv
loop-vectorize
    
loop not vectorized 
os_writev
7932
        PyBuffer_Release(&buf[i]);
inline
        
PyBuffer_Release will not be inlined into iov_cleanup because its definition is unavailable 
iov_cleanup
loop-vectorize
        
loop not vectorized: call instruction cannot be vectorized 
os_readv
loop-vectorize
        
loop not vectorized: call instruction cannot be vectorized 
os_writev
7933
    }
7934
    PyMem_Del(buf);
inline
    
PyMem_Free will not be inlined into iov_cleanup because its definition is unavailable 
iov_cleanup
7935
}
7936
#endif
7937

7938

7939
#ifdef HAVE_READV
7940
/*[clinic input]
7941
os.readv -> Py_ssize_t
7942

7943
    fd: int
7944
    buffers: object
7945
    /
7946

7947
Read from a file descriptor fd into an iterable of buffers.
7948

7949
The buffers should be mutable buffers accepting bytes.
7950
readv will transfer data into each buffer until it is full
7951
and then move on to the next buffer in the sequence to hold
7952
the rest of the data.
7953

7954
readv returns the total number of bytes read,
7955
which may be less than the total capacity of all the buffers.
7956
[clinic start generated code]*/
7957

7958
static Py_ssize_t
7959
os_readv_impl(PyObject *module, int fd, PyObject *buffers)
7960
/*[clinic end generated code: output=792da062d3fcebdb input=e679eb5dbfa0357d]*/
7961
{
7962
    int cnt;
7963
    Py_ssize_t n;
7964
    int async_err = 0;
7965
    struct iovec *iov;
7966
    Py_buffer *buf;
7967

7968
    if (!PySequence_Check(buffers)) {
inline
         
PySequence_Check will not be inlined into os_readv_impl because its definition is unavailable 
os_readv_impl
7969
        PyErr_SetString(PyExc_TypeError,
inline
        
PyErr_SetString will not be inlined into os_readv_impl because its definition is unavailable 
os_readv_impl
gvn
                        
load of type %struct._object* not eliminated because it is clobbered by call 
os_readv_impl
gvn
                        
load of type %struct._object* not eliminated because it is clobbered by call 
os_readv
7970
            "readv() arg 2 must be a sequence");
7971
        return -1;
7972
    }
7973

7974
    cnt = PySequence_Size(buffers);
inline
          
PySequence_Size will not be inlined into os_readv_impl because its definition is unavailable 
os_readv_impl
7975

7976
    if (iov_setup(&iov, &buf, buffers, cnt, PyBUF_WRITABLE) < 0)
inline
        
iov_setup too costly to inline (cost=540, threshold=250) 
os_readv_impl
inline
        
iov_setup will not be inlined into os_readv_impl 
os_readv_impl
inline
        
iov_setup too costly to inline (cost=540, threshold=250) 
os_readv
inline
        
iov_setup will not be inlined into os_readv 
os_readv
7977
        return -1;
7978

7979
    do {
loop-vectorize
    
loop not vectorized: loop control flow is not understood by vectorizer 
os_readv
loop-vectorize
    
loop not vectorized 
os_readv
7980
        Py_BEGIN_ALLOW_THREADS
inline
        
PyEval_SaveThread will not be inlined into os_readv_impl because its definition is unavailable 
os_readv_impl
7981
        n = readv(fd, iov, cnt);
inline
            
readv will not be inlined into os_readv_impl because its definition is unavailable 
os_readv_impl
licm
                      
hosting load 
os_readv_impl
7982
        Py_END_ALLOW_THREADS
inline
        
PyEval_RestoreThread will not be inlined into os_readv_impl because its definition is unavailable 
os_readv_impl
7983
    } while (n < 0 && errno == EINTR && !(async_err = PyErr_CheckSignals()));
inline
                      
__errno_location will not be inlined into os_readv_impl because its definition is unavailable 
os_readv_impl
inline
                                                      
PyErr_CheckSignals will not be inlined into os_readv_impl because its definition is unavailable 
os_readv_impl
7984

7985
    iov_cleanup(iov, buf, cnt);
inline
    
iov_cleanup can be inlined into os_readv_impl with cost=90 (threshold=250) 
os_readv_impl
inline
    
iov_cleanup inlined into os_readv_impl 
os_readv_impl
gvn
                
load of type i8* eliminated in favor of inttoptr 
os_readv_impl
gvn
                     
load of type %struct.bufferinfo* not eliminated because it is clobbered by call 
os_readv_impl
gvn
                     
load of type %struct.bufferinfo* not eliminated because it is clobbered by call 
os_readv
7986
    if (n < 0) {
7987
        if (!async_err)
7988
            posix_error();
inline
            
posix_error can be inlined into os_readv_impl with cost=10 (threshold=375) 
os_readv_impl
inline
            
posix_error inlined into os_readv_impl 
os_readv_impl
7989
        return -1;
7990
    }
7991

7992
    return n;
7993
}
7994
#endif /* HAVE_READV */
7995

7996

7997
#ifdef HAVE_PREAD
7998
/*[clinic input]
7999
# TODO length should be size_t!  but Python doesn't support parsing size_t yet.
8000
os.pread
8001

8002
    fd: int
8003
    length: int
8004
    offset: Py_off_t
8005
    /
8006

8007
Read a number of bytes from a file descriptor starting at a particular offset.
8008

8009
Read length bytes from file descriptor fd, starting at offset bytes from
8010
the beginning of the file.  The file offset remains unchanged.
8011
[clinic start generated code]*/
8012

8013
static PyObject *
8014
os_pread_impl(PyObject *module, int fd, int length, Py_off_t offset)
8015
/*[clinic end generated code: output=435b29ee32b54a78 input=084948dcbaa35d4c]*/
8016
{
8017
    Py_ssize_t n;
8018
    int async_err = 0;
8019
    PyObject *buffer;
8020

8021
    if (length < 0) {
8022
        errno = EINVAL;
inline
        
__errno_location will not be inlined into os_pread_impl because its definition is unavailable 
os_pread_impl
8023
        return posix_error();
inline
               
posix_error can be inlined into os_pread_impl with cost=10 (threshold=375) 
os_pread_impl
inline
               
posix_error inlined into os_pread_impl 
os_pread_impl
8024
    }
8025
    buffer = PyBytes_FromStringAndSize((char *)NULL, length);
inline
             
PyBytes_FromStringAndSize will not be inlined into os_pread_impl because its definition is unavailable 
os_pread_impl
8026
    if (buffer == NULL)
8027
        return NULL;
8028

8029
    do {
loop-vectorize
    
loop not vectorized: loop control flow is not understood by vectorizer 
os_pread
loop-vectorize
    
loop not vectorized 
os_pread
8030
        Py_BEGIN_ALLOW_THREADS
inline
        
PyEval_SaveThread will not be inlined into os_pread_impl because its definition is unavailable 
os_pread_impl
8031
        _Py_BEGIN_SUPPRESS_IPH
8032
        n = pread(fd, PyBytes_AS_STRING(buffer), length, offset);
inline
            
pread64 will not be inlined into os_pread_impl because its definition is unavailable 
os_pread_impl
licm
                      
hosting bitcast 
os_pread_impl
8033
        _Py_END_SUPPRESS_IPH
8034
        Py_END_ALLOW_THREADS
inline
        
PyEval_RestoreThread will not be inlined into os_pread_impl because its definition is unavailable 
os_pread_impl
8035
    } while (n < 0 && errno == EINTR && !(async_err = PyErr_CheckSignals()));
inline
                      
__errno_location will not be inlined into os_pread_impl because its definition is unavailable 
os_pread_impl
inline
                                                      
PyErr_CheckSignals will not be inlined into os_pread_impl because its definition is unavailable 
os_pread_impl
8036

8037
    if (n < 0) {
8038
        Py_DECREF(buffer);
gvn
        
load of type %struct._object* eliminated in favor of call 
os_pread_impl
gvn
        
load of type i64 not eliminated because it is clobbered by call 
os_pread_impl
gvn
        
load of type i64 not eliminated because it is clobbered by call 
os_pread
8039
        return (!async_err) ? posix_error() : NULL;
inline
                              
posix_error can be inlined into os_pread_impl with cost=10 (threshold=375) 
os_pread_impl
inline
                              
posix_error inlined into os_pread_impl 
os_pread_impl
8040
    }
8041
    if (n != length)
8042
        _PyBytes_Resize(&buffer, n);
inline
        
_PyBytes_Resize will not be inlined into os_pread_impl because its definition is unavailable 
os_pread_impl
8043
    return buffer;
gvn
           
load of type %struct._object* not eliminated in favor of store because it is clobbered by call 
os_pread_impl
gvn
           
load eliminated by PRE 
os_pread_impl
8044
}
8045
#endif /* HAVE_PREAD */
8046

8047

8048
/*[clinic input]
8049
os.write -> Py_ssize_t
8050

8051
    fd: int
8052
    data: Py_buffer
8053
    /
8054

8055
Write a bytes object to a file descriptor.
8056
[clinic start generated code]*/
8057

8058
static Py_ssize_t
8059
os_write_impl(PyObject *module, int fd, Py_buffer *data)
8060
/*[clinic end generated code: output=e4ef5bc904b58ef9 input=3207e28963234f3c]*/
8061
{
8062
    return _Py_write(fd, data->buf, data->len);
inline
           
_Py_write will not be inlined into os_write_impl because its definition is unavailable 
os_write_impl
8063
}
8064

8065
#ifdef HAVE_SENDFILE
8066
PyDoc_STRVAR(posix_sendfile__doc__,
8067
"sendfile(out, in, offset, count) -> byteswritten\n\
8068
sendfile(out, in, offset, count[, headers][, trailers], flags=0)\n\
8069
            -> byteswritten\n\
8070
Copy count bytes from file descriptor in to file descriptor out.");
8071

8072
/* AC 3.5: don't bother converting, has optional group*/
8073
static PyObject *
8074
posix_sendfile(PyObject *self, PyObject *args, PyObject *kwdict)
8075
{
8076
    int in, out;
8077
    Py_ssize_t ret;
8078
    int async_err = 0;
8079
    off_t offset;
8080

8081
#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__APPLE__)
8082
#ifndef __APPLE__
8083
    Py_ssize_t len;
8084
#endif
8085
    PyObject *headers = NULL, *trailers = NULL;
8086
    Py_buffer *hbuf, *tbuf;
8087
    off_t sbytes;
8088
    struct sf_hdtr sf;
8089
    int flags = 0;
8090
    /* Beware that "in" clashes with Python's own "in" operator keyword */
8091
    static char *keywords[] = {"out", "in",
8092
                                "offset", "count",
8093
                                "headers", "trailers", "flags", NULL};
8094

8095
    sf.headers = NULL;
8096
    sf.trailers = NULL;
8097

8098
#ifdef __APPLE__
8099
    if (!PyArg_ParseTupleAndKeywords(args, kwdict, "iiO&O&|OOi:sendfile",
8100
        keywords, &out, &in, Py_off_t_converter, &offset, Py_off_t_converter, &sbytes,
8101
#else
8102
    if (!PyArg_ParseTupleAndKeywords(args, kwdict, "iiO&n|OOi:sendfile",
8103
        keywords, &out, &in, Py_off_t_converter, &offset, &len,
8104
#endif
8105
                &headers, &trailers, &flags))
8106
            return NULL;
8107
    if (headers != NULL) {
8108
        if (!PySequence_Check(headers)) {
8109
            PyErr_SetString(PyExc_TypeError,
8110
                "sendfile() headers must be a sequence");
8111
            return NULL;
8112
        } else {
8113
            Py_ssize_t i = 0; /* Avoid uninitialized warning */
8114
            sf.hdr_cnt = PySequence_Size(headers);
8115
            if (sf.hdr_cnt > 0 &&
8116
                (i = iov_setup(&(sf.headers), &hbuf,
8117
                                headers, sf.hdr_cnt, PyBUF_SIMPLE)) < 0)
8118
                return NULL;
8119
#ifdef __APPLE__
8120
            sbytes += i;
8121
#endif
8122
        }
8123
    }
8124
    if (trailers != NULL) {
8125
        if (!PySequence_Check(trailers)) {
8126
            PyErr_SetString(PyExc_TypeError,
8127
                "sendfile() trailers must be a sequence");
8128
            return NULL;
8129
        } else {
8130
            Py_ssize_t i = 0; /* Avoid uninitialized warning */
8131
            sf.trl_cnt = PySequence_Size(trailers);
8132
            if (sf.trl_cnt > 0 &&
8133
                (i = iov_setup(&(sf.trailers), &tbuf,
8134
                                trailers, sf.trl_cnt, PyBUF_SIMPLE)) < 0)
8135
                return NULL;
8136
#ifdef __APPLE__
8137
            sbytes += i;
8138
#endif
8139
        }
8140
    }
8141

8142
    _Py_BEGIN_SUPPRESS_IPH
8143
    do {
8144
        Py_BEGIN_ALLOW_THREADS
8145
#ifdef __APPLE__
8146
        ret = sendfile(in, out, offset, &sbytes, &sf, flags);
8147
#else
8148
        ret = sendfile(in, out, offset, len, &sf, &sbytes, flags);
8149
#endif
8150
        Py_END_ALLOW_THREADS
8151
    } while (ret < 0 && errno == EINTR && !(async_err = PyErr_CheckSignals()));
8152
    _Py_END_SUPPRESS_IPH
8153

8154
    if (sf.headers != NULL)
8155
        iov_cleanup(sf.headers, hbuf, sf.hdr_cnt);
8156
    if (sf.trailers != NULL)
8157
        iov_cleanup(sf.trailers, tbuf, sf.trl_cnt);
8158

8159
    if (ret < 0) {
8160
        if ((errno == EAGAIN) || (errno == EBUSY)) {
8161
            if (sbytes != 0) {
8162
                // some data has been sent
8163
                goto done;
8164
            }
8165
            else {
8166
                // no data has been sent; upper application is supposed
8167
                // to retry on EAGAIN or EBUSY
8168
                return posix_error();
8169
            }
8170
        }
8171
        return (!async_err) ? posix_error() : NULL;
8172
    }
8173
    goto done;
8174

8175
done:
8176
    #if !defined(HAVE_LARGEFILE_SUPPORT)
8177
        return Py_BuildValue("l", sbytes);
8178
    #else
8179
        return Py_BuildValue("L", sbytes);
8180
    #endif
8181

8182
#else
8183
    Py_ssize_t count;
8184
    PyObject *offobj;
8185
    static char *keywords[] = {"out", "in",
8186
                                "offset", "count", NULL};
8187
    if (!PyArg_ParseTupleAndKeywords(args, kwdict, "iiOn:sendfile",
inline
         
_PyArg_ParseTupleAndKeywords_SizeT will not be inlined into posix_sendfile because its definition is unavailable 
posix_sendfile
8188
            keywords, &out, &in, &offobj, &count))
8189
        return NULL;
8190
#ifdef __linux__
8191
    if (offobj == Py_None) {
gvn
        
load of type %struct._object* not eliminated because it is clobbered by call 
posix_sendfile
8192
        do {
loop-vectorize
        
loop not vectorized: loop control flow is not understood by vectorizer 
posix_sendfile
loop-vectorize
        
loop not vectorized 
posix_sendfile
8193
            Py_BEGIN_ALLOW_THREADS
inline
            
PyEval_SaveThread will not be inlined into posix_sendfile because its definition is unavailable 
posix_sendfile
8194
            ret = sendfile(out, in, NULL, count);
inline
                  
sendfile64 will not be inlined into posix_sendfile because its definition is unavailable 
posix_sendfile
licm
                           
failed to move load with loop-invariant address because the loop may invalidate its value 
posix_sendfile
licm
                                
failed to move load with loop-invariant address because the loop may invalidate its value 
posix_sendfile
licm
                                          
failed to move load with loop-invariant address because the loop may invalidate its value 
posix_sendfile
gvn
                           
load of type i32 not eliminated because it is clobbered by call 
posix_sendfile
gvn
                                
load of type i32 not eliminated because it is clobbered by call 
posix_sendfile
gvn
                                          
load of type i64 not eliminated because it is clobbered by call 
posix_sendfile
8195
            Py_END_ALLOW_THREADS
inline
            
PyEval_RestoreThread will not be inlined into posix_sendfile because its definition is unavailable 
posix_sendfile
8196
        } while (ret < 0 && errno == EINTR && !(async_err = PyErr_CheckSignals()));
inline
                            
__errno_location will not be inlined into posix_sendfile because its definition is unavailable 
posix_sendfile
inline
                                                            
PyErr_CheckSignals will not be inlined into posix_sendfile because its definition is unavailable 
posix_sendfile
8197
        if (ret < 0)
8198
            return (!async_err) ? posix_error() : NULL;
inline
                                  
posix_error can be inlined into posix_sendfile with cost=10 (threshold=375) 
posix_sendfile
inline
                                  
posix_error inlined into posix_sendfile 
posix_sendfile
8199
        return Py_BuildValue("n", ret);
inline
               
_Py_BuildValue_SizeT will not be inlined into posix_sendfile because its definition is unavailable 
posix_sendfile
8200
    }
8201
#endif
8202
    if (!Py_off_t_converter(offobj, &offset))
inline
         
Py_off_t_converter can be inlined into posix_sendfile with cost=30 (threshold=375) 
posix_sendfile
inline
         
Py_off_t_converter inlined into posix_sendfile 
posix_sendfile
8203
        return NULL;
8204

8205
    do {
loop-vectorize
    
loop not vectorized: loop control flow is not understood by vectorizer 
posix_sendfile
loop-vectorize
    
loop not vectorized 
posix_sendfile
8206
        Py_BEGIN_ALLOW_THREADS
inline
        
PyEval_SaveThread will not be inlined into posix_sendfile because its definition is unavailable 
posix_sendfile
8207
        ret = sendfile(out, in, &offset, count);
inline
              
sendfile64 will not be inlined into posix_sendfile because its definition is unavailable 
posix_sendfile
licm
                       
failed to move load with loop-invariant address because the loop may invalidate its value 
posix_sendfile
licm
                            
failed to move load with loop-invariant address because the loop may invalidate its value 
posix_sendfile
licm
                                         
failed to move load with loop-invariant address because the loop may invalidate its value 
posix_sendfile
gvn
                       
load of type i32 not eliminated because it is clobbered by call 
posix_sendfile
gvn
                            
load of type i32 not eliminated because it is clobbered by call 
posix_sendfile
gvn
                                         
load of type i64 not eliminated because it is clobbered by call 
posix_sendfile
8208
        Py_END_ALLOW_THREADS
inline
        
PyEval_RestoreThread will not be inlined into posix_sendfile because its definition is unavailable 
posix_sendfile
8209
    } while (ret < 0 && errno == EINTR && !(async_err = PyErr_CheckSignals()));
inline
                        
__errno_location will not be inlined into posix_sendfile because its definition is unavailable 
posix_sendfile
inline
                                                        
PyErr_CheckSignals will not be inlined into posix_sendfile because its definition is unavailable 
posix_sendfile
8210
    if (ret < 0)
8211
        return (!async_err) ? posix_error() : NULL;
inline
                              
posix_error can be inlined into posix_sendfile with cost=10 (threshold=375) 
posix_sendfile
inline
                              
posix_error inlined into posix_sendfile 
posix_sendfile
8212
    return Py_BuildValue("n", ret);
inline
           
_Py_BuildValue_SizeT will not be inlined into posix_sendfile because its definition is unavailable 
posix_sendfile
8213
#endif
8214
}
8215
#endif /* HAVE_SENDFILE */
8216

8217

8218
/*[clinic input]
8219
os.fstat
8220

8221
    fd : int
8222

8223
Perform a stat system call on the given file descriptor.
8224

8225
Like stat(), but for an open file descriptor.
8226
Equivalent to os.stat(fd).
8227
[clinic start generated code]*/
8228

8229
static PyObject *
8230
os_fstat_impl(PyObject *module, int fd)
8231
/*[clinic end generated code: output=efc038cb5f654492 input=27e0e0ebbe5600c9]*/
8232
{
8233
    STRUCT_STAT st;
8234
    int res;
8235
    int async_err = 0;
8236

8237
    do {
loop-vectorize
    
loop not vectorized: loop control flow is not understood by vectorizer 
os_fstat
loop-vectorize
    
loop not vectorized 
os_fstat
8238
        Py_BEGIN_ALLOW_THREADS
inline
        
PyEval_SaveThread will not be inlined into os_fstat_impl because its definition is unavailable 
os_fstat_impl
8239
        res = FSTAT(fd, &st);
inline
              
fstat64 can be inlined into os_fstat_impl with cost=5 (threshold=487) 
os_fstat_impl
inline
              
fstat64 inlined into os_fstat_impl 
os_fstat_impl
licm
              
hosting bitcast 
os_fstat_impl
8240
        Py_END_ALLOW_THREADS
inline
        
PyEval_RestoreThread will not be inlined into os_fstat_impl because its definition is unavailable 
os_fstat_impl
8241
    } while (res != 0 && errno == EINTR && !(async_err = PyErr_CheckSignals()));
inline
                         
__errno_location will not be inlined into os_fstat_impl because its definition is unavailable 
os_fstat_impl
inline
                                                         
PyErr_CheckSignals will not be inlined into os_fstat_impl because its definition is unavailable 
os_fstat_impl
8242
    if (res != 0) {
8243
#ifdef MS_WINDOWS
8244
        return PyErr_SetFromWindowsErr(0);
8245
#else
8246
        return (!async_err) ? posix_error() : NULL;
inline
                              
posix_error can be inlined into os_fstat_impl with cost=10 (threshold=375) 
os_fstat_impl
inline
                              
posix_error inlined into os_fstat_impl 
os_fstat_impl
8247
#endif
8248
    }
8249

8250
    return _pystat_fromstructstat(&st);
inline
           
_pystat_fromstructstat too costly to inline (cost=645, threshold=625) 
os_fstat_impl
inline
           
_pystat_fromstructstat will not be inlined into os_fstat_impl 
os_fstat_impl
inline
           
_pystat_fromstructstat too costly to inline (cost=645, threshold=625) 
os_fstat
inline
           
_pystat_fromstructstat will not be inlined into os_fstat 
os_fstat
8251
}
8252

8253

8254
/*[clinic input]
8255
os.isatty -> bool
8256
    fd: int
8257
    /
8258

8259
Return True if the fd is connected to a terminal.
8260

8261
Return True if the file descriptor is an open file descriptor
8262
connected to the slave end of a terminal.
8263
[clinic start generated code]*/
8264

8265
static int
8266
os_isatty_impl(PyObject *module, int fd)
8267
/*[clinic end generated code: output=6a48c8b4e644ca00 input=08ce94aa1eaf7b5e]*/
8268
{
8269
    int return_value;
8270
    _Py_BEGIN_SUPPRESS_IPH
8271
    return_value = isatty(fd);
inline
                   
isatty will not be inlined into os_isatty_impl because its definition is unavailable 
os_isatty_impl
8272
    _Py_END_SUPPRESS_IPH
8273
    return return_value;
8274
}
8275

8276

8277
#ifdef HAVE_PIPE
8278
/*[clinic input]
8279
os.pipe
8280

8281
Create a pipe.
8282

8283
Returns a tuple of two file descriptors:
8284
  (read_fd, write_fd)
8285
[clinic start generated code]*/
8286

8287
static PyObject *
8288
os_pipe_impl(PyObject *module)
8289
/*[clinic end generated code: output=ff9b76255793b440 input=02535e8c8fa6c4d4]*/
8290
{
8291
    int fds[2];
8292
#ifdef MS_WINDOWS
8293
    HANDLE read, write;
8294
    SECURITY_ATTRIBUTES attr;
8295
    BOOL ok;
8296
#else
8297
    int res;
8298
#endif
8299

8300
#ifdef MS_WINDOWS
8301
    attr.nLength = sizeof(attr);
8302
    attr.lpSecurityDescriptor = NULL;
8303
    attr.bInheritHandle = FALSE;
8304

8305
    Py_BEGIN_ALLOW_THREADS
8306
    _Py_BEGIN_SUPPRESS_IPH
8307
    ok = CreatePipe(&read, &write, &attr, 0);
8308
    if (ok) {
8309
        fds[0] = _open_osfhandle((intptr_t)read, _O_RDONLY);
8310
        fds[1] = _open_osfhandle((intptr_t)write, _O_WRONLY);
8311
        if (fds[0] == -1 || fds[1] == -1) {
8312
            CloseHandle(read);
8313
            CloseHandle(write);
8314
            ok = 0;
8315
        }
8316
    }
8317
    _Py_END_SUPPRESS_IPH
8318
    Py_END_ALLOW_THREADS
8319

8320
    if (!ok)
8321
        return PyErr_SetFromWindowsErr(0);
8322
#else
8323

8324
#ifdef HAVE_PIPE2
8325
    Py_BEGIN_ALLOW_THREADS
inline
    
PyEval_SaveThread will not be inlined into os_pipe_impl because its definition is unavailable 
os_pipe_impl
8326
    res = pipe2(fds, O_CLOEXEC);
inline
          
pipe2 will not be inlined into os_pipe_impl because its definition is unavailable 
os_pipe_impl
8327
    Py_END_ALLOW_THREADS
inline
    
PyEval_RestoreThread will not be inlined into os_pipe_impl because its definition is unavailable 
os_pipe_impl
8328

8329
    if (res != 0 && errno == ENOSYS)
inline
                    
__errno_location will not be inlined into os_pipe_impl because its definition is unavailable 
os_pipe_impl
8330
    {
8331
#endif
8332
        Py_BEGIN_ALLOW_THREADS
inline
        
PyEval_SaveThread will not be inlined into os_pipe_impl because its definition is unavailable 
os_pipe_impl
8333
        res = pipe(fds);
inline
              
pipe will not be inlined into os_pipe_impl because its definition is unavailable 
os_pipe_impl
8334
        Py_END_ALLOW_THREADS
inline
        
PyEval_RestoreThread will not be inlined into os_pipe_impl because its definition is unavailable 
os_pipe_impl
8335

8336
        if (res == 0) {
8337
            if (_Py_set_inheritable(fds[0], 0, NULL) < 0) {
inline
                
_Py_set_inheritable will not be inlined into os_pipe_impl because its definition is unavailable 
os_pipe_impl
gvn
                                    
load of type i32 not eliminated because it is clobbered by call 
os_pipe_impl
gvn
                                    
load of type i32 not eliminated because it is clobbered by call 
os_pipe
8338
                close(fds[0]);
inline
                
close will not be inlined into os_pipe_impl because its definition is unavailable 
os_pipe_impl
gvn
                      
load of type i32 not eliminated in favor of load because it is clobbered by call 
os_pipe_impl
gvn
                      
load of type i32 not eliminated in favor of load because it is clobbered by call 
os_pipe
8339
                close(fds[1]);
inline
                
close will not be inlined into os_pipe_impl because its definition is unavailable 
os_pipe_impl
gvn
                      
load of type i32 not eliminated because it is clobbered by call 
os_pipe_impl
gvn
                      
load of type i32 not eliminated because it is clobbered by call 
os_pipe
8340
                return NULL;
8341
            }
8342
            if (_Py_set_inheritable(fds[1], 0, NULL) < 0) {
inline
                
_Py_set_inheritable will not be inlined into os_pipe_impl because its definition is unavailable 
os_pipe_impl
gvn
                                    
load of type i32 not eliminated because it is clobbered by call 
os_pipe_impl
gvn
                                    
load of type i32 not eliminated because it is clobbered by call 
os_pipe
8343
                close(fds[0]);
inline
                
close will not be inlined into os_pipe_impl because its definition is unavailable 
os_pipe_impl
gvn
                      
load of type i32 not eliminated in favor of load because it is clobbered by call 
os_pipe_impl
gvn
                      
load of type i32 not eliminated in favor of load because it is clobbered by call 
os_pipe
8344
                close(fds[1]);
inline
                
close will not be inlined into os_pipe_impl because its definition is unavailable 
os_pipe_impl
gvn
                      
load of type i32 not eliminated in favor of load because it is clobbered by call 
os_pipe_impl
gvn
                      
load of type i32 not eliminated in favor of load because it is clobbered by call 
os_pipe
8345
                return NULL;
8346
            }
8347
        }
8348
#ifdef HAVE_PIPE2
8349
    }
8350
#endif
8351

8352
    if (res != 0)
8353
        return PyErr_SetFromErrno(PyExc_OSError);
inline
               
PyErr_SetFromErrno will not be inlined into os_pipe_impl because its definition is unavailable 
os_pipe_impl
gvn
                                  
load of type %struct._object* not eliminated because it is clobbered by call 
os_pipe_impl
gvn
                                  
load of type %struct._object* not eliminated because it is clobbered by call 
os_pipe
8354
#endif /* !MS_WINDOWS */
8355
    return Py_BuildValue("(ii)", fds[0], fds[1]);
inline
           
_Py_BuildValue_SizeT will not be inlined into os_pipe_impl because its definition is unavailable 
os_pipe_impl
gvn
                                 
load of type i32 not eliminated because it is clobbered by call 
os_pipe_impl
gvn
                                         
load of type i32 not eliminated because it is clobbered by call 
os_pipe_impl
gvn
                                 
load of type i32 not eliminated because it is clobbered by call 
os_pipe
gvn
                                         
load of type i32 not eliminated because it is clobbered by call 
os_pipe
8356
}
8357
#endif  /* HAVE_PIPE */
8358

8359

8360
#ifdef HAVE_PIPE2
8361
/*[clinic input]
8362
os.pipe2
8363

8364
    flags: int
8365
    /
8366

8367
Create a pipe with flags set atomically.
8368

8369
Returns a tuple of two file descriptors:
8370
  (read_fd, write_fd)
8371

8372
flags can be constructed by ORing together one or more of these values:
8373
O_NONBLOCK, O_CLOEXEC.
8374
[clinic start generated code]*/
8375

8376
static PyObject *
8377
os_pipe2_impl(PyObject *module, int flags)
8378
/*[clinic end generated code: output=25751fb43a45540f input=f261b6e7e63c6817]*/
8379
{
8380
    int fds[2];
8381
    int res;
8382

8383
    res = pipe2(fds, flags);
inline
          
pipe2 will not be inlined into os_pipe2_impl because its definition is unavailable 
os_pipe2_impl
8384
    if (res != 0)
8385
        return posix_error();
inline
               
posix_error can be inlined into os_pipe2_impl with cost=10 (threshold=375) 
os_pipe2_impl
inline
               
posix_error inlined into os_pipe2_impl 
os_pipe2_impl
8386
    return Py_BuildValue("(ii)", fds[0], fds[1]);
inline
           
_Py_BuildValue_SizeT will not be inlined into os_pipe2_impl because its definition is unavailable 
os_pipe2_impl
gvn
                                 
load of type i32 not eliminated because it is clobbered by call 
os_pipe2_impl
gvn
                                         
load of type i32 not eliminated because it is clobbered by call 
os_pipe2_impl
gvn
                                 
load of type i32 not eliminated because it is clobbered by call 
os_pipe2
gvn
                                         
load of type i32 not eliminated because it is clobbered by call 
os_pipe2
8387
}
8388
#endif /* HAVE_PIPE2 */
8389

8390

8391
#ifdef HAVE_WRITEV
8392
/*[clinic input]
8393
os.writev -> Py_ssize_t
8394
    fd: int
8395
    buffers: object
8396
    /
8397

8398
Iterate over buffers, and write the contents of each to a file descriptor.
8399

8400
Returns the total number of bytes written.
8401
buffers must be a sequence of bytes-like objects.
8402
[clinic start generated code]*/
8403

8404
static Py_ssize_t
8405
os_writev_impl(PyObject *module, int fd, PyObject *buffers)
8406
/*[clinic end generated code: output=56565cfac3aac15b input=5b8d17fe4189d2fe]*/
8407
{
8408
    int cnt;
8409
    Py_ssize_t result;
8410
    int async_err = 0;
8411
    struct iovec *iov;
8412
    Py_buffer *buf;
8413

8414
    if (!PySequence_Check(buffers)) {
inline
         
PySequence_Check will not be inlined into os_writev_impl because its definition is unavailable 
os_writev_impl
8415
        PyErr_SetString(PyExc_TypeError,
inline
        
PyErr_SetString will not be inlined into os_writev_impl because its definition is unavailable 
os_writev_impl
gvn
                        
load of type %struct._object* not eliminated because it is clobbered by call 
os_writev_impl
gvn
                        
load of type %struct._object* not eliminated because it is clobbered by call 
os_writev
8416
            "writev() arg 2 must be a sequence");
8417
        return -1;
8418
    }
8419
    cnt = PySequence_Size(buffers);
inline
          
PySequence_Size will not be inlined into os_writev_impl because its definition is unavailable 
os_writev_impl
8420

8421
    if (iov_setup(&iov, &buf, buffers, cnt, PyBUF_SIMPLE) < 0) {
inline
        
iov_setup too costly to inline (cost=540, threshold=250) 
os_writev_impl
inline
        
iov_setup will not be inlined into os_writev_impl 
os_writev_impl
inline
        
iov_setup too costly to inline (cost=540, threshold=250) 
os_writev
inline
        
iov_setup will not be inlined into os_writev 
os_writev
8422
        return -1;
8423
    }
8424

8425
    do {
loop-vectorize
    
loop not vectorized: loop control flow is not understood by vectorizer 
os_writev
loop-vectorize
    
loop not vectorized 
os_writev
8426
        Py_BEGIN_ALLOW_THREADS
inline
        
PyEval_SaveThread will not be inlined into os_writev_impl because its definition is unavailable 
os_writev_impl
8427
        result = writev(fd, iov, cnt);
inline
                 
writev will not be inlined into os_writev_impl because its definition is unavailable 
os_writev_impl
licm
                            
hosting load 
os_writev_impl
8428
        Py_END_ALLOW_THREADS
inline
        
PyEval_RestoreThread will not be inlined into os_writev_impl because its definition is unavailable 
os_writev_impl
8429
    } while (result < 0 && errno == EINTR && !(async_err = PyErr_CheckSignals()));
inline
                           
__errno_location will not be inlined into os_writev_impl because its definition is unavailable 
os_writev_impl
inline
                                                           
PyErr_CheckSignals will not be inlined into os_writev_impl because its definition is unavailable 
os_writev_impl
8430

8431
    iov_cleanup(iov, buf, cnt);
inline
    
iov_cleanup can be inlined into os_writev_impl with cost=-14910 (threshold=250) 
os_writev_impl
inline
    
iov_cleanup inlined into os_writev_impl 
os_writev_impl
gvn
                
load of type i8* eliminated in favor of inttoptr 
os_writev_impl
gvn
                     
load of type %struct.bufferinfo* not eliminated because it is clobbered by call 
os_writev_impl
gvn
                     
load of type %struct.bufferinfo* not eliminated because it is clobbered by call 
os_writev
8432
    if (result < 0 && !async_err)
8433
        posix_error();
inline
        
posix_error can be inlined into os_writev_impl with cost=10 (threshold=375) 
os_writev_impl
inline
        
posix_error inlined into os_writev_impl 
os_writev_impl
8434

8435
    return result;
8436
}
8437
#endif /* HAVE_WRITEV */
8438

8439

8440
#ifdef HAVE_PWRITE
8441
/*[clinic input]
8442
os.pwrite -> Py_ssize_t
8443

8444
    fd: int
8445
    buffer: Py_buffer
8446
    offset: Py_off_t
8447
    /
8448

8449
Write bytes to a file descriptor starting at a particular offset.
8450

8451
Write buffer to fd, starting at offset bytes from the beginning of
8452
the file.  Returns the number of bytes writte.  Does not change the
8453
current file offset.
8454
[clinic start generated code]*/
8455

8456
static Py_ssize_t
8457
os_pwrite_impl(PyObject *module, int fd, Py_buffer *buffer, Py_off_t offset)
8458
/*[clinic end generated code: output=c74da630758ee925 input=19903f1b3dd26377]*/
8459
{
8460
    Py_ssize_t size;
8461
    int async_err = 0;
8462

8463
    do {
loop-vectorize
    
loop not vectorized: loop control flow is not understood by vectorizer 
os_pwrite
loop-vectorize
    
loop not vectorized 
os_pwrite
8464
        Py_BEGIN_ALLOW_THREADS
inline
        
PyEval_SaveThread will not be inlined into os_pwrite_impl because its definition is unavailable 
os_pwrite_impl
8465
        _Py_BEGIN_SUPPRESS_IPH
8466
        size = pwrite(fd, buffer->buf, (size_t)buffer->len, offset);
inline
               
pwrite64 will not be inlined into os_pwrite_impl because its definition is unavailable 
os_pwrite_impl
licm
                                  
hosting getelementptr 
os_pwrite_impl
licm
                                  
failed to move load with loop-invariant address because the loop may invalidate its value 
os_pwrite_impl
licm
                                                       
hosting getelementptr 
os_pwrite_impl
licm
                                                       
failed to move load with loop-invariant address because the loop may invalidate its value 
os_pwrite_impl
gvn
                                  
load of type i8* not eliminated because it is clobbered by call 
os_pwrite_impl
gvn
                                                       
load of type i64 not eliminated because it is clobbered by call 
os_pwrite_impl
licm
                                  
failed to move load with loop-invariant address because the loop may invalidate its value 
os_pwrite
licm
                                                       
failed to move load with loop-invariant address because the loop may invalidate its value 
os_pwrite
gvn
                                  
load of type i8* not eliminated because it is clobbered by call 
os_pwrite
gvn
                                                       
load of type i64 not eliminated because it is clobbered by call 
os_pwrite
8467
        _Py_END_SUPPRESS_IPH
8468
        Py_END_ALLOW_THREADS
inline
        
PyEval_RestoreThread will not be inlined into os_pwrite_impl because its definition is unavailable 
os_pwrite_impl
8469
    } while (size < 0 && errno == EINTR && !(async_err = PyErr_CheckSignals()));
inline
                         
__errno_location will not be inlined into os_pwrite_impl because its definition is unavailable 
os_pwrite_impl
inline
                                                         
PyErr_CheckSignals will not be inlined into os_pwrite_impl because its definition is unavailable 
os_pwrite_impl
8470

8471
    if (size < 0 && !async_err)
8472
        posix_error();
inline
        
posix_error can be inlined into os_pwrite_impl with cost=10 (threshold=375) 
os_pwrite_impl
inline
        
posix_error inlined into os_pwrite_impl 
os_pwrite_impl
8473
    return size;
8474
}
8475
#endif /* HAVE_PWRITE */
8476

8477

8478
#ifdef HAVE_MKFIFO
8479
/*[clinic input]
8480
os.mkfifo
8481

8482
    path: path_t
8483
    mode: int=0o666
8484
    *
8485
    dir_fd: dir_fd(requires='mkfifoat')=None
8486

8487
Create a "fifo" (a POSIX named pipe).
8488

8489
If dir_fd is not None, it should be a file descriptor open to a directory,
8490
  and path should be relative; path will then be relative to that directory.
8491
dir_fd may not be implemented on your platform.
8492
  If it is unavailable, using it will raise a NotImplementedError.
8493
[clinic start generated code]*/
8494

8495
static PyObject *
8496
os_mkfifo_impl(PyObject *module, path_t *path, int mode, int dir_fd)
8497
/*[clinic end generated code: output=ce41cfad0e68c940 input=73032e98a36e0e19]*/
8498
{
8499
    int result;
8500
    int async_err = 0;
8501

8502
    do {
loop-vectorize
    
loop not vectorized: loop control flow is not understood by vectorizer 
os_mkfifo
loop-vectorize
    
loop not vectorized 
os_mkfifo
8503
        Py_BEGIN_ALLOW_THREADS
inline
        
PyEval_SaveThread will not be inlined into os_mkfifo_impl because its definition is unavailable 
os_mkfifo_impl
8504
#ifdef HAVE_MKFIFOAT
8505
        if (dir_fd != DEFAULT_DIR_FD)
licm
                   
hosting icmp 
os_mkfifo_impl
8506
            result = mkfifoat(dir_fd, path->narrow, mode);
inline
                     
mkfifoat will not be inlined into os_mkfifo_impl because its definition is unavailable 
os_mkfifo_impl
licm
                                            
hosting getelementptr 
os_mkfifo_impl
licm
                                            
failed to move load with loop-invariant address because the loop may invalidate its value 
os_mkfifo_impl
gvn
                                            
load of type i8* not eliminated because it is clobbered by call 
os_mkfifo_impl
licm
                                            
failed to move load with loop-invariant address because the loop may invalidate its value 
os_mkfifo
gvn
                                            
load of type i8* not eliminated because it is clobbered by call 
os_mkfifo
8507
        else
8508
#endif
8509
            result = mkfifo(path->narrow, mode);
inline
                     
mkfifo will not be inlined into os_mkfifo_impl because its definition is unavailable 
os_mkfifo_impl
8510
        Py_END_ALLOW_THREADS
inline
        
PyEval_RestoreThread will not be inlined into os_mkfifo_impl because its definition is unavailable 
os_mkfifo_impl
8511
    } while (result != 0 && errno == EINTR &&
inline
                            
__errno_location will not be inlined into os_mkfifo_impl because its definition is unavailable 
os_mkfifo_impl
8512
             !(async_err = PyErr_CheckSignals()));
inline
                           
PyErr_CheckSignals will not be inlined into os_mkfifo_impl because its definition is unavailable 
os_mkfifo_impl
8513
    if (result != 0)
8514
        return (!async_err) ? posix_error() : NULL;
inline
                              
posix_error can be inlined into os_mkfifo_impl with cost=10 (threshold=375) 
os_mkfifo_impl
inline
                              
posix_error inlined into os_mkfifo_impl 
os_mkfifo_impl
8515

8516
    Py_RETURN_NONE;
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_mkfifo_impl
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_mkfifo
8517
}
8518
#endif /* HAVE_MKFIFO */
8519

8520

8521
#if defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)
8522
/*[clinic input]
8523
os.mknod
8524

8525
    path: path_t
8526
    mode: int=0o600
8527
    device: dev_t=0
8528
    *
8529
    dir_fd: dir_fd(requires='mknodat')=None
8530

8531
Create a node in the file system.
8532

8533
Create a node in the file system (file, device special file or named pipe)
8534
at path.  mode specifies both the permissions to use and the
8535
type of node to be created, being combined (bitwise OR) with one of
8536
S_IFREG, S_IFCHR, S_IFBLK, and S_IFIFO.  If S_IFCHR or S_IFBLK is set on mode,
8537
device defines the newly created device special file (probably using
8538
os.makedev()).  Otherwise device is ignored.
8539

8540
If dir_fd is not None, it should be a file descriptor open to a directory,
8541
  and path should be relative; path will then be relative to that directory.
8542
dir_fd may not be implemented on your platform.
8543
  If it is unavailable, using it will raise a NotImplementedError.
8544
[clinic start generated code]*/
8545

8546
static PyObject *
8547
os_mknod_impl(PyObject *module, path_t *path, int mode, dev_t device,
8548
              int dir_fd)
8549
/*[clinic end generated code: output=92e55d3ca8917461 input=ee44531551a4d83b]*/
8550
{
8551
    int result;
8552
    int async_err = 0;
8553

8554
    do {
loop-vectorize
    
loop not vectorized: loop control flow is not understood by vectorizer 
os_mknod
loop-vectorize
    
loop not vectorized 
os_mknod
8555
        Py_BEGIN_ALLOW_THREADS
inline
        
PyEval_SaveThread will not be inlined into os_mknod_impl because its definition is unavailable 
os_mknod_impl
8556
#ifdef HAVE_MKNODAT
8557
        if (dir_fd != DEFAULT_DIR_FD)
licm
                   
hosting icmp 
os_mknod_impl
8558
            result = mknodat(dir_fd, path->narrow, mode, device);
inline
                     
mknodat can be inlined into os_mknod_impl with cost=15 (threshold=487) 
os_mknod_impl
inline
                     
mknodat inlined into os_mknod_impl 
os_mknod_impl
licm
                                           
hosting getelementptr 
os_mknod_impl
licm
                                           
failed to move load with loop-invariant address because the loop may invalidate its value 
os_mknod_impl
gvn
                                           
load of type i8* not eliminated because it is clobbered by call 
os_mknod_impl
licm
                                           
failed to move load with loop-invariant address because the loop may invalidate its value 
os_mknod
gvn
                                           
load of type i8* not eliminated because it is clobbered by call 
os_mknod
8559
        else
8560
#endif
8561
            result = mknod(path->narrow, mode, device);
inline
                     
mknod can be inlined into os_mknod_impl with cost=15 (threshold=487) 
os_mknod_impl
inline
                     
mknod inlined into os_mknod_impl 
os_mknod_impl
8562
        Py_END_ALLOW_THREADS
inline
        
PyEval_RestoreThread will not be inlined into os_mknod_impl because its definition is unavailable 
os_mknod_impl
8563
    } while (result != 0 && errno == EINTR &&
inline
                            
__errno_location will not be inlined into os_mknod_impl because its definition is unavailable 
os_mknod_impl
8564
             !(async_err = PyErr_CheckSignals()));
inline
                           
PyErr_CheckSignals will not be inlined into os_mknod_impl because its definition is unavailable 
os_mknod_impl
8565
    if (result != 0)
8566
        return (!async_err) ? posix_error() : NULL;
inline
                              
posix_error can be inlined into os_mknod_impl with cost=10 (threshold=375) 
os_mknod_impl
inline
                              
posix_error inlined into os_mknod_impl 
os_mknod_impl
8567

8568
    Py_RETURN_NONE;
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_mknod_impl
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_mknod
8569
}
8570
#endif /* defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV) */
8571

8572

8573
#ifdef HAVE_DEVICE_MACROS
8574
/*[clinic input]
8575
os.major -> unsigned_int
8576

8577
    device: dev_t
8578
    /
8579

8580
Extracts a device major number from a raw device number.
8581
[clinic start generated code]*/
8582

8583
static unsigned int
8584
os_major_impl(PyObject *module, dev_t device)
8585
/*[clinic end generated code: output=5b3b2589bafb498e input=1e16a4d30c4d4462]*/
8586
{
8587
    return major(device);
inline
           
gnu_dev_major can be inlined into os_major_impl with cost=-10 (threshold=487) 
os_major_impl
inline
           
gnu_dev_major inlined into os_major_impl 
os_major_impl
8588
}
8589

8590

8591
/*[clinic input]
8592
os.minor -> unsigned_int
8593

8594
    device: dev_t
8595
    /
8596

8597
Extracts a device minor number from a raw device number.
8598
[clinic start generated code]*/
8599

8600
static unsigned int
8601
os_minor_impl(PyObject *module, dev_t device)
8602
/*[clinic end generated code: output=5e1a25e630b0157d input=0842c6d23f24c65e]*/
8603
{
8604
    return minor(device);
inline
           
gnu_dev_minor can be inlined into os_minor_impl with cost=-15 (threshold=487) 
os_minor_impl
inline
           
gnu_dev_minor inlined into os_minor_impl 
os_minor_impl
8605
}
8606

8607

8608
/*[clinic input]
8609
os.makedev -> dev_t
8610

8611
    major: int
8612
    minor: int
8613
    /
8614

8615
Composes a raw device number from the major and minor device numbers.
8616
[clinic start generated code]*/
8617

8618
static dev_t
8619
os_makedev_impl(PyObject *module, int major, int minor)
8620
/*[clinic end generated code: output=881aaa4aba6f6a52 input=4b9fd8fc73cbe48f]*/
8621
{
8622
    return makedev(major, minor);
inline
           
gnu_dev_makedev can be inlined into os_makedev_impl with cost=10 (threshold=487) 
os_makedev_impl
inline
           
gnu_dev_makedev inlined into os_makedev_impl 
os_makedev_impl
8623
}
8624
#endif /* HAVE_DEVICE_MACROS */
8625

8626

8627
#if defined HAVE_FTRUNCATE || defined MS_WINDOWS
8628
/*[clinic input]
8629
os.ftruncate
8630

8631
    fd: int
8632
    length: Py_off_t
8633
    /
8634

8635
Truncate a file, specified by file descriptor, to a specific length.
8636
[clinic start generated code]*/
8637

8638
static PyObject *
8639
os_ftruncate_impl(PyObject *module, int fd, Py_off_t length)
8640
/*[clinic end generated code: output=fba15523721be7e4 input=63b43641e52818f2]*/
8641
{
8642
    int result;
8643
    int async_err = 0;
8644

8645
    do {
loop-vectorize
    
loop not vectorized: loop control flow is not understood by vectorizer 
os_ftruncate
loop-vectorize
    
loop not vectorized 
os_ftruncate
loop-vectorize
    
loop not vectorized: loop control flow is not understood by vectorizer 
os_truncate
loop-vectorize
    
loop not vectorized 
os_truncate
8646
        Py_BEGIN_ALLOW_THREADS
inline
        
PyEval_SaveThread will not be inlined into os_ftruncate_impl because its definition is unavailable 
os_ftruncate_impl
8647
        _Py_BEGIN_SUPPRESS_IPH
8648
#ifdef MS_WINDOWS
8649
        result = _chsize_s(fd, length);
8650
#else
8651
        result = ftruncate(fd, length);
inline
                 
ftruncate64 will not be inlined into os_ftruncate_impl because its definition is unavailable 
os_ftruncate_impl
8652
#endif
8653
        _Py_END_SUPPRESS_IPH
8654
        Py_END_ALLOW_THREADS
inline
        
PyEval_RestoreThread will not be inlined into os_ftruncate_impl because its definition is unavailable 
os_ftruncate_impl
8655
    } while (result != 0 && errno == EINTR &&
inline
                            
__errno_location will not be inlined into os_ftruncate_impl because its definition is unavailable 
os_ftruncate_impl
8656
             !(async_err = PyErr_CheckSignals()));
inline
                           
PyErr_CheckSignals will not be inlined into os_ftruncate_impl because its definition is unavailable 
os_ftruncate_impl
8657
    if (result != 0)
8658
        return (!async_err) ? posix_error() : NULL;
inline
                              
posix_error can be inlined into os_ftruncate_impl with cost=10 (threshold=375) 
os_ftruncate_impl
inline
                              
posix_error inlined into os_ftruncate_impl 
os_ftruncate_impl
8659
    Py_RETURN_NONE;
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_ftruncate_impl
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_ftruncate
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_truncate_impl
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_truncate
8660
}
8661
#endif /* HAVE_FTRUNCATE || MS_WINDOWS */
8662

8663

8664
#if defined HAVE_TRUNCATE || defined MS_WINDOWS
8665
/*[clinic input]
8666
os.truncate
8667
    path: path_t(allow_fd='PATH_HAVE_FTRUNCATE')
8668
    length: Py_off_t
8669

8670
Truncate a file, specified by path, to a specific length.
8671

8672
On some platforms, path may also be specified as an open file descriptor.
8673
  If this functionality is unavailable, using it raises an exception.
8674
[clinic start generated code]*/
8675

8676
static PyObject *
8677
os_truncate_impl(PyObject *module, path_t *path, Py_off_t length)
8678
/*[clinic end generated code: output=43009c8df5c0a12b input=77229cf0b50a9b77]*/
8679
{
8680
    int result;
8681
#ifdef MS_WINDOWS
8682
    int fd;
8683
#endif
8684

8685
    if (path->fd != -1)
gvn
              
load of type i32 not eliminated in favor of store because it is clobbered by call 
os_truncate
8686
        return os_ftruncate_impl(module, path->fd, length);
inline
               
os_ftruncate_impl can be inlined into os_truncate_impl with cost=-14785 (threshold=250) 
os_truncate_impl
inline
               
os_ftruncate_impl inlined into os_truncate_impl 
os_truncate_impl
8687

8688
    Py_BEGIN_ALLOW_THREADS
inline
    
PyEval_SaveThread will not be inlined into os_truncate_impl because its definition is unavailable 
os_truncate_impl
8689
    _Py_BEGIN_SUPPRESS_IPH
8690
#ifdef MS_WINDOWS
8691
    fd = _wopen(path->wide, _O_WRONLY | _O_BINARY | _O_NOINHERIT);
8692
    if (fd < 0)
8693
        result = -1;
8694
    else {
8695
        result = _chsize_s(fd, length);
8696
        close(fd);
8697
        if (result < 0)
8698
            errno = result;
8699
    }
8700
#else
8701
    result = truncate(path->narrow, length);
inline
             
truncate64 will not be inlined into os_truncate_impl because its definition is unavailable 
os_truncate_impl
gvn
                            
load of type i8* not eliminated because it is clobbered by call 
os_truncate_impl
gvn
                            
load of type i8* not eliminated because it is clobbered by call 
os_truncate
8702
#endif
8703
    _Py_END_SUPPRESS_IPH
8704
    Py_END_ALLOW_THREADS
inline
    
PyEval_RestoreThread will not be inlined into os_truncate_impl because its definition is unavailable 
os_truncate_impl
8705
    if (result < 0)
8706
        return path_error(path);
inline
               
path_error can be inlined into os_truncate_impl with cost=10 (threshold=375) 
os_truncate_impl
inline
               
path_error inlined into os_truncate_impl 
os_truncate_impl
8707

8708
    Py_RETURN_NONE;
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_truncate_impl
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_truncate
8709
}
8710
#endif /* HAVE_TRUNCATE || MS_WINDOWS */
8711

8712

8713
/* Issue #22396: On 32-bit AIX platform, the prototypes of os.posix_fadvise()
8714
   and os.posix_fallocate() in system headers are wrong if _LARGE_FILES is
8715
   defined, which is the case in Python on AIX. AIX bug report:
8716
   http://www-01.ibm.com/support/docview.wss?uid=isg1IV56170 */
8717
#if defined(_AIX) && defined(_LARGE_FILES) && !defined(__64BIT__)
8718
#  define POSIX_FADVISE_AIX_BUG
8719
#endif
8720

8721

8722
#if defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG)
8723
/*[clinic input]
8724
os.posix_fallocate
8725

8726
    fd: int
8727
    offset: Py_off_t
8728
    length: Py_off_t
8729
    /
8730

8731
Ensure a file has allocated at least a particular number of bytes on disk.
8732

8733
Ensure that the file specified by fd encompasses a range of bytes
8734
starting at offset bytes from the beginning and continuing for length bytes.
8735
[clinic start generated code]*/
8736

8737
static PyObject *
8738
os_posix_fallocate_impl(PyObject *module, int fd, Py_off_t offset,
8739
                        Py_off_t length)
8740
/*[clinic end generated code: output=73f107139564aa9d input=d7a2ef0ab2ca52fb]*/
8741
{
8742
    int result;
8743
    int async_err = 0;
8744

8745
    do {
loop-vectorize
    
loop not vectorized: loop control flow is not understood by vectorizer 
os_posix_fallocate
loop-vectorize
    
loop not vectorized 
os_posix_fallocate
8746
        Py_BEGIN_ALLOW_THREADS
inline
        
PyEval_SaveThread will not be inlined into os_posix_fallocate_impl because its definition is unavailable 
os_posix_fallocate_impl
8747
        result = posix_fallocate(fd, offset, length);
inline
                 
posix_fallocate64 will not be inlined into os_posix_fallocate_impl because its definition is unavailable 
os_posix_fallocate_impl
8748
        Py_END_ALLOW_THREADS
inline
        
PyEval_RestoreThread will not be inlined into os_posix_fallocate_impl because its definition is unavailable 
os_posix_fallocate_impl
8749
    } while (result != 0 && errno == EINTR &&
inline
                            
__errno_location will not be inlined into os_posix_fallocate_impl because its definition is unavailable 
os_posix_fallocate_impl
8750
             !(async_err = PyErr_CheckSignals()));
inline
                           
PyErr_CheckSignals will not be inlined into os_posix_fallocate_impl because its definition is unavailable 
os_posix_fallocate_impl
8751
    if (result != 0)
8752
        return (!async_err) ? posix_error() : NULL;
inline
                              
posix_error can be inlined into os_posix_fallocate_impl with cost=10 (threshold=375) 
os_posix_fallocate_impl
inline
                              
posix_error inlined into os_posix_fallocate_impl 
os_posix_fallocate_impl
8753
    Py_RETURN_NONE;
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_posix_fallocate_impl
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_posix_fallocate
8754
}
8755
#endif /* HAVE_POSIX_FALLOCATE) && !POSIX_FADVISE_AIX_BUG */
8756

8757

8758
#if defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG)
8759
/*[clinic input]
8760
os.posix_fadvise
8761

8762
    fd: int
8763
    offset: Py_off_t
8764
    length: Py_off_t
8765
    advice: int
8766
    /
8767

8768
Announce an intention to access data in a specific pattern.
8769

8770
Announce an intention to access data in a specific pattern, thus allowing
8771
the kernel to make optimizations.
8772
The advice applies to the region of the file specified by fd starting at
8773
offset and continuing for length bytes.
8774
advice is one of POSIX_FADV_NORMAL, POSIX_FADV_SEQUENTIAL,
8775
POSIX_FADV_RANDOM, POSIX_FADV_NOREUSE, POSIX_FADV_WILLNEED, or
8776
POSIX_FADV_DONTNEED.
8777
[clinic start generated code]*/
8778

8779
static PyObject *
8780
os_posix_fadvise_impl(PyObject *module, int fd, Py_off_t offset,
8781
                      Py_off_t length, int advice)
8782
/*[clinic end generated code: output=412ef4aa70c98642 input=0fbe554edc2f04b5]*/
8783
{
8784
    int result;
8785
    int async_err = 0;
8786

8787
    do {
loop-vectorize
    
loop not vectorized: loop control flow is not understood by vectorizer 
os_posix_fadvise
loop-vectorize
    
loop not vectorized 
os_posix_fadvise
8788
        Py_BEGIN_ALLOW_THREADS
inline
        
PyEval_SaveThread will not be inlined into os_posix_fadvise_impl because its definition is unavailable 
os_posix_fadvise_impl
8789
        result = posix_fadvise(fd, offset, length, advice);
inline
                 
posix_fadvise64 will not be inlined into os_posix_fadvise_impl because its definition is unavailable 
os_posix_fadvise_impl
8790
        Py_END_ALLOW_THREADS
inline
        
PyEval_RestoreThread will not be inlined into os_posix_fadvise_impl because its definition is unavailable 
os_posix_fadvise_impl
8791
    } while (result != 0 && errno == EINTR &&
inline
                            
__errno_location will not be inlined into os_posix_fadvise_impl because its definition is unavailable 
os_posix_fadvise_impl
8792
             !(async_err = PyErr_CheckSignals()));
inline
                           
PyErr_CheckSignals will not be inlined into os_posix_fadvise_impl because its definition is unavailable 
os_posix_fadvise_impl
8793
    if (result != 0)
8794
        return (!async_err) ? posix_error() : NULL;
inline
                              
posix_error can be inlined into os_posix_fadvise_impl with cost=10 (threshold=375) 
os_posix_fadvise_impl
inline
                              
posix_error inlined into os_posix_fadvise_impl 
os_posix_fadvise_impl
8795
    Py_RETURN_NONE;
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_posix_fadvise_impl
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_posix_fadvise
8796
}
8797
#endif /* HAVE_POSIX_FADVISE && !POSIX_FADVISE_AIX_BUG */
8798

8799
#ifdef HAVE_PUTENV
8800

8801
/* Save putenv() parameters as values here, so we can collect them when they
8802
 * get re-set with another call for the same key. */
8803
static PyObject *posix_putenv_garbage;
8804

8805
static void
8806
posix_putenv_garbage_setitem(PyObject *name, PyObject *value)
8807
{
8808
    /* Install the first arg and newstr in posix_putenv_garbage;
8809
     * this will cause previous value to be collected.  This has to
8810
     * happen after the real putenv() call because the old value
8811
     * was still accessible until then. */
8812
    if (PyDict_SetItem(posix_putenv_garbage, name, value))
inline
        
PyDict_SetItem will not be inlined into posix_putenv_garbage_setitem because its definition is unavailable 
posix_putenv_garbage_setitem
gvn
                       
load of type %struct._object* not eliminated because it is clobbered by call 
os_putenv_impl
gvn
                       
load of type %struct._object* not eliminated because it is clobbered by call 
os_putenv
8813
        /* really not much we can do; just leak */
8814
        PyErr_Clear();
inline
        
PyErr_Clear will not be inlined into posix_putenv_garbage_setitem because its definition is unavailable 
posix_putenv_garbage_setitem
8815
    else
8816
        Py_DECREF(value);
gvn
        
load of type i64 not eliminated because it is clobbered by call 
posix_putenv_garbage_setitem
gvn
        
load of type i64 not eliminated because it is clobbered by call 
os_putenv_impl
gvn
        
load of type i64 not eliminated because it is clobbered by call 
os_putenv
8817
}
8818

8819

8820
#ifdef MS_WINDOWS
8821
/*[clinic input]
8822
os.putenv
8823

8824
    name: unicode
8825
    value: unicode
8826
    /
8827

8828
Change or add an environment variable.
8829
[clinic start generated code]*/
8830

8831
static PyObject *
8832
os_putenv_impl(PyObject *module, PyObject *name, PyObject *value)
8833
/*[clinic end generated code: output=d29a567d6b2327d2 input=ba586581c2e6105f]*/
8834
{
8835
    const wchar_t *env;
8836

8837
    PyObject *unicode = PyUnicode_FromFormat("%U=%U", name, value);
8838
    if (unicode == NULL) {
8839
        PyErr_NoMemory();
8840
        return NULL;
8841
    }
8842
    if (_MAX_ENV < PyUnicode_GET_LENGTH(unicode)) {
8843
        PyErr_Format(PyExc_ValueError,
8844
                     "the environment variable is longer than %u characters",
8845
                     _MAX_ENV);
8846
        goto error;
8847
    }
8848

8849
    env = PyUnicode_AsUnicode(unicode);
8850
    if (env == NULL)
8851
        goto error;
8852
    if (_wputenv(env)) {
8853
        posix_error();
8854
        goto error;
8855
    }
8856

8857
    posix_putenv_garbage_setitem(name, unicode);
8858
    Py_RETURN_NONE;
8859

8860
error:
8861
    Py_DECREF(unicode);
8862
    return NULL;
8863
}
8864
#else /* MS_WINDOWS */
8865
/*[clinic input]
8866
os.putenv
8867

8868
    name: FSConverter
8869
    value: FSConverter
8870
    /
8871

8872
Change or add an environment variable.
8873
[clinic start generated code]*/
8874

8875
static PyObject *
8876
os_putenv_impl(PyObject *module, PyObject *name, PyObject *value)
8877
/*[clinic end generated code: output=d29a567d6b2327d2 input=a97bc6152f688d31]*/
8878
{
8879
    PyObject *bytes = NULL;
8880
    char *env;
8881
    const char *name_string = PyBytes_AsString(name);
inline
                              
PyBytes_AsString will not be inlined into os_putenv_impl because its definition is unavailable 
os_putenv_impl
8882
    const char *value_string = PyBytes_AsString(value);
inline
                               
PyBytes_AsString will not be inlined into os_putenv_impl because its definition is unavailable 
os_putenv_impl
8883

8884
    bytes = PyBytes_FromFormat("%s=%s", name_string, value_string);
inline
            
PyBytes_FromFormat will not be inlined into os_putenv_impl because its definition is unavailable 
os_putenv_impl
8885
    if (bytes == NULL) {
8886
        PyErr_NoMemory();
inline
        
PyErr_NoMemory will not be inlined into os_putenv_impl because its definition is unavailable 
os_putenv_impl
8887
        return NULL;
8888
    }
8889

8890
    env = PyBytes_AS_STRING(bytes);
8891
    if (putenv(env)) {
inline
        
putenv will not be inlined into os_putenv_impl because its definition is unavailable 
os_putenv_impl
8892
        Py_DECREF(bytes);
gvn
        
load of type i64 not eliminated because it is clobbered by call 
os_putenv_impl
gvn
        
load of type i64 not eliminated because it is clobbered by call 
os_putenv
8893
        return posix_error();
inline
               
posix_error can be inlined into os_putenv_impl with cost=10 (threshold=375) 
os_putenv_impl
inline
               
posix_error inlined into os_putenv_impl 
os_putenv_impl
8894
    }
8895

8896
    posix_putenv_garbage_setitem(name, bytes);
inline
    
posix_putenv_garbage_setitem can be inlined into os_putenv_impl with cost=-14905 (threshold=250) 
os_putenv_impl
inline
    
posix_putenv_garbage_setitem inlined into os_putenv_impl 
os_putenv_impl
8897
    Py_RETURN_NONE;
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_putenv_impl
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_putenv
8898
}
8899
#endif /* MS_WINDOWS */
8900
#endif /* HAVE_PUTENV */
8901

8902

8903
#ifdef HAVE_UNSETENV
8904
/*[clinic input]
8905
os.unsetenv
8906
    name: FSConverter
8907
    /
8908

8909
Delete an environment variable.
8910
[clinic start generated code]*/
8911

8912
static PyObject *
8913
os_unsetenv_impl(PyObject *module, PyObject *name)
8914
/*[clinic end generated code: output=54c4137ab1834f02 input=2bb5288a599c7107]*/
8915
{
8916
#ifndef HAVE_BROKEN_UNSETENV
8917
    int err;
8918
#endif
8919

8920
#ifdef HAVE_BROKEN_UNSETENV
8921
    unsetenv(PyBytes_AS_STRING(name));
8922
#else
8923
    err = unsetenv(PyBytes_AS_STRING(name));
inline
          
unsetenv will not be inlined into os_unsetenv_impl because its definition is unavailable 
os_unsetenv_impl
8924
    if (err)
8925
        return posix_error();
inline
               
posix_error can be inlined into os_unsetenv_impl with cost=10 (threshold=375) 
os_unsetenv_impl
inline
               
posix_error inlined into os_unsetenv_impl 
os_unsetenv_impl
8926
#endif
8927

8928
    /* Remove the key from posix_putenv_garbage;
8929
     * this will cause it to be collected.  This has to
8930
     * happen after the real unsetenv() call because the
8931
     * old value was still accessible until then.
8932
     */
8933
    if (PyDict_DelItem(posix_putenv_garbage, name)) {
inline
        
PyDict_DelItem will not be inlined into os_unsetenv_impl because its definition is unavailable 
os_unsetenv_impl
gvn
                       
load of type %struct._object* not eliminated because it is clobbered by call 
os_unsetenv_impl
gvn
                       
load of type %struct._object* not eliminated because it is clobbered by call 
os_unsetenv
8934
        /* really not much we can do; just leak */
8935
        PyErr_Clear();
inline
        
PyErr_Clear will not be inlined into os_unsetenv_impl because its definition is unavailable 
os_unsetenv_impl
8936
    }
8937
    Py_RETURN_NONE;
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_unsetenv_impl
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_unsetenv
8938
}
8939
#endif /* HAVE_UNSETENV */
8940

8941

8942
/*[clinic input]
8943
os.strerror
8944

8945
    code: int
8946
    /
8947

8948
Translate an error code to a message string.
8949
[clinic start generated code]*/
8950

8951
static PyObject *
8952
os_strerror_impl(PyObject *module, int code)
8953
/*[clinic end generated code: output=baebf09fa02a78f2 input=75a8673d97915a91]*/
8954
{
8955
    char *message = strerror(code);
inline
                    
strerror will not be inlined into os_strerror_impl because its definition is unavailable 
os_strerror_impl
8956
    if (message == NULL) {
8957
        PyErr_SetString(PyExc_ValueError,
inline
        
PyErr_SetString will not be inlined into os_strerror_impl because its definition is unavailable 
os_strerror_impl
gvn
                        
load of type %struct._object* not eliminated because it is clobbered by call 
os_strerror_impl
gvn
                        
load of type %struct._object* not eliminated because it is clobbered by call 
os_strerror
8958
                        "strerror() argument out of range");
8959
        return NULL;
8960
    }
8961
    return PyUnicode_DecodeLocale(message, "surrogateescape");
inline
           
PyUnicode_DecodeLocale will not be inlined into os_strerror_impl because its definition is unavailable 
os_strerror_impl
8962
}
8963

8964

8965
#ifdef HAVE_SYS_WAIT_H
8966
#ifdef WCOREDUMP
8967
/*[clinic input]
8968
os.WCOREDUMP -> bool
8969

8970
    status: int
8971
    /
8972

8973
Return True if the process returning status was dumped to a core file.
8974
[clinic start generated code]*/
8975

8976
static int
8977
os_WCOREDUMP_impl(PyObject *module, int status)
8978
/*[clinic end generated code: output=1a584b147b16bd18 input=8b05e7ab38528d04]*/
8979
{
8980
    WAIT_TYPE wait_status;
8981
    WAIT_STATUS_INT(wait_status) = status;
8982
    return WCOREDUMP(wait_status);
8983
}
8984
#endif /* WCOREDUMP */
8985

8986

8987
#ifdef WIFCONTINUED
8988
/*[clinic input]
8989
os.WIFCONTINUED -> bool
8990

8991
    status: int
8992

8993
Return True if a particular process was continued from a job control stop.
8994

8995
Return True if the process returning status was continued from a
8996
job control stop.
8997
[clinic start generated code]*/
8998

8999
static int
9000
os_WIFCONTINUED_impl(PyObject *module, int status)
9001
/*[clinic end generated code: output=1e35295d844364bd input=e777e7d38eb25bd9]*/
9002
{
9003
    WAIT_TYPE wait_status;
9004
    WAIT_STATUS_INT(wait_status) = status;
9005
    return WIFCONTINUED(wait_status);
9006
}
9007
#endif /* WIFCONTINUED */
9008

9009

9010
#ifdef WIFSTOPPED
9011
/*[clinic input]
9012
os.WIFSTOPPED -> bool
9013

9014
    status: int
9015

9016
Return True if the process returning status was stopped.
9017
[clinic start generated code]*/
9018

9019
static int
9020
os_WIFSTOPPED_impl(PyObject *module, int status)
9021
/*[clinic end generated code: output=fdb57122a5c9b4cb input=043cb7f1289ef904]*/
9022
{
9023
    WAIT_TYPE wait_status;
9024
    WAIT_STATUS_INT(wait_status) = status;
9025
    return WIFSTOPPED(wait_status);
9026
}
9027
#endif /* WIFSTOPPED */
9028

9029

9030
#ifdef WIFSIGNALED
9031
/*[clinic input]
9032
os.WIFSIGNALED -> bool
9033

9034
    status: int
9035

9036
Return True if the process returning status was terminated by a signal.
9037
[clinic start generated code]*/
9038

9039
static int
9040
os_WIFSIGNALED_impl(PyObject *module, int status)
9041
/*[clinic end generated code: output=d1dde4dcc819a5f5 input=d55ba7cc9ce5dc43]*/
9042
{
9043
    WAIT_TYPE wait_status;
9044
    WAIT_STATUS_INT(wait_status) = status;
9045
    return WIFSIGNALED(wait_status);
9046
}
9047
#endif /* WIFSIGNALED */
9048

9049

9050
#ifdef WIFEXITED
9051
/*[clinic input]
9052
os.WIFEXITED -> bool
9053

9054
    status: int
9055

9056
Return True if the process returning status exited via the exit() system call.
9057
[clinic start generated code]*/
9058

9059
static int
9060
os_WIFEXITED_impl(PyObject *module, int status)
9061
/*[clinic end generated code: output=01c09d6ebfeea397 input=d63775a6791586c0]*/
9062
{
9063
    WAIT_TYPE wait_status;
9064
    WAIT_STATUS_INT(wait_status) = status;
9065
    return WIFEXITED(wait_status);
9066
}
9067
#endif /* WIFEXITED */
9068

9069

9070
#ifdef WEXITSTATUS
9071
/*[clinic input]
9072
os.WEXITSTATUS -> int
9073

9074
    status: int
9075

9076
Return the process return code from status.
9077
[clinic start generated code]*/
9078

9079
static int
9080
os_WEXITSTATUS_impl(PyObject *module, int status)
9081
/*[clinic end generated code: output=6e3efbba11f6488d input=e1fb4944e377585b]*/
9082
{
9083
    WAIT_TYPE wait_status;
9084
    WAIT_STATUS_INT(wait_status) = status;
9085
    return WEXITSTATUS(wait_status);
9086
}
9087
#endif /* WEXITSTATUS */
9088

9089

9090
#ifdef WTERMSIG
9091
/*[clinic input]
9092
os.WTERMSIG -> int
9093

9094
    status: int
9095

9096
Return the signal that terminated the process that provided the status value.
9097
[clinic start generated code]*/
9098

9099
static int
9100
os_WTERMSIG_impl(PyObject *module, int status)
9101
/*[clinic end generated code: output=172f7dfc8dcfc3ad input=727fd7f84ec3f243]*/
9102
{
9103
    WAIT_TYPE wait_status;
9104
    WAIT_STATUS_INT(wait_status) = status;
9105
    return WTERMSIG(wait_status);
9106
}
9107
#endif /* WTERMSIG */
9108

9109

9110
#ifdef WSTOPSIG
9111
/*[clinic input]
9112
os.WSTOPSIG -> int
9113

9114
    status: int
9115

9116
Return the signal that stopped the process that provided the status value.
9117
[clinic start generated code]*/
9118

9119
static int
9120
os_WSTOPSIG_impl(PyObject *module, int status)
9121
/*[clinic end generated code: output=0ab7586396f5d82b input=46ebf1d1b293c5c1]*/
9122
{
9123
    WAIT_TYPE wait_status;
9124
    WAIT_STATUS_INT(wait_status) = status;
9125
    return WSTOPSIG(wait_status);
9126
}
9127
#endif /* WSTOPSIG */
9128
#endif /* HAVE_SYS_WAIT_H */
9129

9130

9131
#if defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H)
9132
#ifdef _SCO_DS
9133
/* SCO OpenServer 5.0 and later requires _SVID3 before it reveals the
9134
   needed definitions in sys/statvfs.h */
9135
#define _SVID3
9136
#endif
9137
#include <sys/statvfs.h>
9138

9139
static PyObject*
9140
_pystatvfs_fromstructstatvfs(struct statvfs st) {
9141
    PyObject *v = PyStructSequence_New(&StatVFSResultType);
inline
                  
PyStructSequence_New will not be inlined into _pystatvfs_fromstructstatvfs because its definition is unavailable 
_pystatvfs_fromstructstatvfs
9142
    if (v == NULL)
9143
        return NULL;
9144

9145
#if !defined(HAVE_LARGEFILE_SUPPORT)
9146
    PyStructSequence_SET_ITEM(v, 0, PyLong_FromLong((long) st.f_bsize));
inline
    
PyLong_FromLong will not be inlined into _pystatvfs_fromstructstatvfs because its definition is unavailable 
_pystatvfs_fromstructstatvfs
9147
    PyStructSequence_SET_ITEM(v, 1, PyLong_FromLong((long) st.f_frsize));
inline
    
PyLong_FromLong will not be inlined into _pystatvfs_fromstructstatvfs because its definition is unavailable 
_pystatvfs_fromstructstatvfs
9148
    PyStructSequence_SET_ITEM(v, 2, PyLong_FromLong((long) st.f_blocks));
inline
    
PyLong_FromLong will not be inlined into _pystatvfs_fromstructstatvfs because its definition is unavailable 
_pystatvfs_fromstructstatvfs
9149
    PyStructSequence_SET_ITEM(v, 3, PyLong_FromLong((long) st.f_bfree));
inline
    
PyLong_FromLong will not be inlined into _pystatvfs_fromstructstatvfs because its definition is unavailable 
_pystatvfs_fromstructstatvfs
9150
    PyStructSequence_SET_ITEM(v, 4, PyLong_FromLong((long) st.f_bavail));
inline
    
PyLong_FromLong will not be inlined into _pystatvfs_fromstructstatvfs because its definition is unavailable 
_pystatvfs_fromstructstatvfs
9151
    PyStructSequence_SET_ITEM(v, 5, PyLong_FromLong((long) st.f_files));
inline
    
PyLong_FromLong will not be inlined into _pystatvfs_fromstructstatvfs because its definition is unavailable 
_pystatvfs_fromstructstatvfs
9152
    PyStructSequence_SET_ITEM(v, 6, PyLong_FromLong((long) st.f_ffree));
inline
    
PyLong_FromLong will not be inlined into _pystatvfs_fromstructstatvfs because its definition is unavailable 
_pystatvfs_fromstructstatvfs
9153
    PyStructSequence_SET_ITEM(v, 7, PyLong_FromLong((long) st.f_favail));
inline
    
PyLong_FromLong will not be inlined into _pystatvfs_fromstructstatvfs because its definition is unavailable 
_pystatvfs_fromstructstatvfs
9154
    PyStructSequence_SET_ITEM(v, 8, PyLong_FromLong((long) st.f_flag));
inline
    
PyLong_FromLong will not be inlined into _pystatvfs_fromstructstatvfs because its definition is unavailable 
_pystatvfs_fromstructstatvfs
9155
    PyStructSequence_SET_ITEM(v, 9, PyLong_FromLong((long) st.f_namemax));
inline
    
PyLong_FromLong will not be inlined into _pystatvfs_fromstructstatvfs because its definition is unavailable 
_pystatvfs_fromstructstatvfs
9156
#else
9157
    PyStructSequence_SET_ITEM(v, 0, PyLong_FromLong((long) st.f_bsize));
9158
    PyStructSequence_SET_ITEM(v, 1, PyLong_FromLong((long) st.f_frsize));
9159
    PyStructSequence_SET_ITEM(v, 2,
9160
                              PyLong_FromLongLong((long long) st.f_blocks));
9161
    PyStructSequence_SET_ITEM(v, 3,
9162
                              PyLong_FromLongLong((long long) st.f_bfree));
9163
    PyStructSequence_SET_ITEM(v, 4,
9164
                              PyLong_FromLongLong((long long) st.f_bavail));
9165
    PyStructSequence_SET_ITEM(v, 5,
9166
                              PyLong_FromLongLong((long long) st.f_files));
9167
    PyStructSequence_SET_ITEM(v, 6,
9168
                              PyLong_FromLongLong((long long) st.f_ffree));
9169
    PyStructSequence_SET_ITEM(v, 7,
9170
                              PyLong_FromLongLong((long long) st.f_favail));
9171
    PyStructSequence_SET_ITEM(v, 8, PyLong_FromLong((long) st.f_flag));
9172
    PyStructSequence_SET_ITEM(v, 9, PyLong_FromLong((long) st.f_namemax));
9173
#endif
9174
    if (PyErr_Occurred()) {
inline
        
PyErr_Occurred will not be inlined into _pystatvfs_fromstructstatvfs because its definition is unavailable 
_pystatvfs_fromstructstatvfs
9175
        Py_DECREF(v);
gvn
        
load of type i64 not eliminated because it is clobbered by call 
_pystatvfs_fromstructstatvfs
9176
        return NULL;
9177
    }
9178

9179
    return v;
9180
}
9181

9182

9183
/*[clinic input]
9184
os.fstatvfs
9185
    fd: int
9186
    /
9187

9188
Perform an fstatvfs system call on the given fd.
9189

9190
Equivalent to statvfs(fd).
9191
[clinic start generated code]*/
9192

9193
static PyObject *
9194
os_fstatvfs_impl(PyObject *module, int fd)
9195
/*[clinic end generated code: output=53547cf0cc55e6c5 input=d8122243ac50975e]*/
9196
{
9197
    int result;
9198
    int async_err = 0;
9199
    struct statvfs st;
9200

9201
    do {
loop-vectorize
    
loop not vectorized: loop control flow is not understood by vectorizer 
os_fstatvfs
loop-vectorize
    
loop not vectorized 
os_fstatvfs
9202
        Py_BEGIN_ALLOW_THREADS
inline
        
PyEval_SaveThread will not be inlined into os_fstatvfs_impl because its definition is unavailable 
os_fstatvfs_impl
9203
        result = fstatvfs(fd, &st);
inline
                 
fstatvfs64 will not be inlined into os_fstatvfs_impl because its definition is unavailable 
os_fstatvfs_impl
9204
        Py_END_ALLOW_THREADS
inline
        
PyEval_RestoreThread will not be inlined into os_fstatvfs_impl because its definition is unavailable 
os_fstatvfs_impl
9205
    } while (result != 0 && errno == EINTR &&
inline
                            
__errno_location will not be inlined into os_fstatvfs_impl because its definition is unavailable 
os_fstatvfs_impl
9206
             !(async_err = PyErr_CheckSignals()));
inline
                           
PyErr_CheckSignals will not be inlined into os_fstatvfs_impl because its definition is unavailable 
os_fstatvfs_impl
9207
    if (result != 0)
9208
        return (!async_err) ? posix_error() : NULL;
inline
                              
posix_error can be inlined into os_fstatvfs_impl with cost=10 (threshold=375) 
os_fstatvfs_impl
inline
                              
posix_error inlined into os_fstatvfs_impl 
os_fstatvfs_impl
9209

9210
    return _pystatvfs_fromstructstatvfs(st);
inline
           
_pystatvfs_fromstructstatvfs too costly to inline (cost=420, threshold=250) 
os_fstatvfs_impl
inline
           
_pystatvfs_fromstructstatvfs will not be inlined into os_fstatvfs_impl 
os_fstatvfs_impl
inline
           
_pystatvfs_fromstructstatvfs too costly to inline (cost=420, threshold=250) 
os_fstatvfs
inline
           
_pystatvfs_fromstructstatvfs will not be inlined into os_fstatvfs 
os_fstatvfs
9211
}
9212
#endif /* defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H) */
9213

9214

9215
#if defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H)
9216
#include <sys/statvfs.h>
9217
/*[clinic input]
9218
os.statvfs
9219

9220
    path: path_t(allow_fd='PATH_HAVE_FSTATVFS')
9221

9222
Perform a statvfs system call on the given path.
9223

9224
path may always be specified as a string.
9225
On some platforms, path may also be specified as an open file descriptor.
9226
  If this functionality is unavailable, using it raises an exception.
9227
[clinic start generated code]*/
9228

9229
static PyObject *
9230
os_statvfs_impl(PyObject *module, path_t *path)
9231
/*[clinic end generated code: output=87106dd1beb8556e input=3f5c35791c669bd9]*/
9232
{
9233
    int result;
9234
    struct statvfs st;
9235

9236
    Py_BEGIN_ALLOW_THREADS
inline
    
PyEval_SaveThread will not be inlined into os_statvfs_impl because its definition is unavailable 
os_statvfs_impl
9237
#ifdef HAVE_FSTATVFS
9238
    if (path->fd != -1) {
gvn
              
load of type i32 not eliminated because it is clobbered by call 
os_statvfs_impl
gvn
              
load of type i32 not eliminated in favor of store because it is clobbered by call 
os_statvfs
9239
#ifdef __APPLE__
9240
        /* handle weak-linking on Mac OS X 10.3 */
9241
        if (fstatvfs == NULL) {
9242
            fd_specified("statvfs", path->fd);
9243
            return NULL;
9244
        }
9245
#endif
9246
        result = fstatvfs(path->fd, &st);
inline
                 
fstatvfs64 will not be inlined into os_statvfs_impl because its definition is unavailable 
os_statvfs_impl
9247
    }
9248
    else
9249
#endif
9250
        result = statvfs(path->narrow, &st);
inline
                 
statvfs64 will not be inlined into os_statvfs_impl because its definition is unavailable 
os_statvfs_impl
gvn
                               
load of type i8* not eliminated because it is clobbered by call 
os_statvfs_impl
gvn
                               
load of type i8* not eliminated because it is clobbered by call 
os_statvfs
9251
    Py_END_ALLOW_THREADS
inline
    
PyEval_RestoreThread will not be inlined into os_statvfs_impl because its definition is unavailable 
os_statvfs_impl
9252

9253
    if (result) {
9254
        return path_error(path);
inline
               
path_error can be inlined into os_statvfs_impl with cost=10 (threshold=375) 
os_statvfs_impl
inline
               
path_error inlined into os_statvfs_impl 
os_statvfs_impl
9255
    }
9256

9257
    return _pystatvfs_fromstructstatvfs(st);
inline
           
_pystatvfs_fromstructstatvfs too costly to inline (cost=420, threshold=250) 
os_statvfs_impl
inline
           
_pystatvfs_fromstructstatvfs will not be inlined into os_statvfs_impl 
os_statvfs_impl
inline
           
_pystatvfs_fromstructstatvfs too costly to inline (cost=420, threshold=250) 
os_statvfs
inline
           
_pystatvfs_fromstructstatvfs will not be inlined into os_statvfs 
os_statvfs
9258
}
9259
#endif /* defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H) */
9260

9261

9262
#ifdef MS_WINDOWS
9263
/*[clinic input]
9264
os._getdiskusage
9265

9266
    path: Py_UNICODE
9267

9268
Return disk usage statistics about the given path as a (total, free) tuple.
9269
[clinic start generated code]*/
9270

9271
static PyObject *
9272
os__getdiskusage_impl(PyObject *module, Py_UNICODE *path)
9273
/*[clinic end generated code: output=76d6adcd86b1db0b input=6458133aed893c78]*/
9274
{
9275
    BOOL retval;
9276
    ULARGE_INTEGER _, total, free;
9277

9278
    Py_BEGIN_ALLOW_THREADS
9279
    retval = GetDiskFreeSpaceExW(path, &_, &total, &free);
9280
    Py_END_ALLOW_THREADS
9281
    if (retval == 0)
9282
        return PyErr_SetFromWindowsErr(0);
9283

9284
    return Py_BuildValue("(LL)", total.QuadPart, free.QuadPart);
9285
}
9286
#endif /* MS_WINDOWS */
9287

9288

9289
/* This is used for fpathconf(), pathconf(), confstr() and sysconf().
9290
 * It maps strings representing configuration variable names to
9291
 * integer values, allowing those functions to be called with the
9292
 * magic names instead of polluting the module's namespace with tons of
9293
 * rarely-used constants.  There are three separate tables that use
9294
 * these definitions.
9295
 *
9296
 * This code is always included, even if none of the interfaces that
9297
 * need it are included.  The #if hackery needed to avoid it would be
9298
 * sufficiently pervasive that it's not worth the loss of readability.
9299
 */
9300
struct constdef {
9301
    const char *name;
9302
    int value;
9303
};
9304

9305
static int
9306
conv_confname(PyObject *arg, int *valuep, struct constdef *table,
9307
              size_t tablesize)
9308
{
9309
    if (PyLong_Check(arg)) {
9310
        int value = _PyLong_AsInt(arg);
inline
                    
_PyLong_AsInt will not be inlined into conv_confname because its definition is unavailable 
conv_confname
9311
        if (value == -1 && PyErr_Occurred())
inline
                           
PyErr_Occurred will not be inlined into conv_confname because its definition is unavailable 
conv_confname
9312
            return 0;
9313
        *valuep = value;
9314
        return 1;
9315
    }
9316
    else {
9317
        /* look up the value in the table using a binary search */
9318
        size_t lo = 0;
9319
        size_t mid;
9320
        size_t hi = tablesize;
9321
        int cmp;
9322
        const char *confname;
9323
        if (!PyUnicode_Check(arg)) {
9324
            PyErr_SetString(PyExc_TypeError,
inline
            
PyErr_SetString will not be inlined into conv_confname because its definition is unavailable 
conv_confname
9325
                "configuration names must be strings or integers");
9326
            return 0;
9327
        }
9328
        confname = PyUnicode_AsUTF8(arg);
inline
                   
PyUnicode_AsUTF8 will not be inlined into conv_confname because its definition is unavailable 
conv_confname
9329
        if (confname == NULL)
9330
            return 0;
9331
        while (lo < hi) {
loop-vectorize
        
loop not vectorized: loop control flow is not understood by vectorizer 
conv_confname
loop-vectorize
        
loop not vectorized 
conv_confname
9332
            mid = (lo + hi) / 2;
9333
            cmp = strcmp(confname, table[mid].name);
inline
                  
strcmp will not be inlined into conv_confname because its definition is unavailable 
conv_confname
9334
            if (cmp < 0)
9335
                hi = mid;
9336
            else if (cmp > 0)
9337
                lo = mid + 1;
9338
            else {
9339
                *valuep = table[mid].value;
9340
                return 1;
9341
            }
9342
        }
9343
        PyErr_SetString(PyExc_ValueError, "unrecognized configuration name");
inline
        
PyErr_SetString will not be inlined into conv_confname because its definition is unavailable 
conv_confname
gvn
                        
load of type %struct._object* not eliminated because it is clobbered by call 
conv_confname
9344
        return 0;
9345
    }
9346
}
9347

9348

9349
#if defined(HAVE_FPATHCONF) || defined(HAVE_PATHCONF)
9350
static struct constdef  posix_constants_pathconf[] = {
9351
#ifdef _PC_ABI_AIO_XFER_MAX
9352
    {"PC_ABI_AIO_XFER_MAX",     _PC_ABI_AIO_XFER_MAX},
9353
#endif
9354
#ifdef _PC_ABI_ASYNC_IO
9355
    {"PC_ABI_ASYNC_IO", _PC_ABI_ASYNC_IO},
9356
#endif
9357
#ifdef _PC_ASYNC_IO
9358
    {"PC_ASYNC_IO",     _PC_ASYNC_IO},
9359
#endif
9360
#ifdef _PC_CHOWN_RESTRICTED
9361
    {"PC_CHOWN_RESTRICTED",     _PC_CHOWN_RESTRICTED},
9362
#endif
9363
#ifdef _PC_FILESIZEBITS
9364
    {"PC_FILESIZEBITS", _PC_FILESIZEBITS},
9365
#endif
9366
#ifdef _PC_LAST
9367
    {"PC_LAST", _PC_LAST},
9368
#endif
9369
#ifdef _PC_LINK_MAX
9370
    {"PC_LINK_MAX",     _PC_LINK_MAX},
9371
#endif
9372
#ifdef _PC_MAX_CANON
9373
    {"PC_MAX_CANON",    _PC_MAX_CANON},
9374
#endif
9375
#ifdef _PC_MAX_INPUT
9376
    {"PC_MAX_INPUT",    _PC_MAX_INPUT},
9377
#endif
9378
#ifdef _PC_NAME_MAX
9379
    {"PC_NAME_MAX",     _PC_NAME_MAX},
9380
#endif
9381
#ifdef _PC_NO_TRUNC
9382
    {"PC_NO_TRUNC",     _PC_NO_TRUNC},
9383
#endif
9384
#ifdef _PC_PATH_MAX
9385
    {"PC_PATH_MAX",     _PC_PATH_MAX},
9386
#endif
9387
#ifdef _PC_PIPE_BUF
9388
    {"PC_PIPE_BUF",     _PC_PIPE_BUF},
9389
#endif
9390
#ifdef _PC_PRIO_IO
9391
    {"PC_PRIO_IO",      _PC_PRIO_IO},
9392
#endif
9393
#ifdef _PC_SOCK_MAXBUF
9394
    {"PC_SOCK_MAXBUF",  _PC_SOCK_MAXBUF},
9395
#endif
9396
#ifdef _PC_SYNC_IO
9397
    {"PC_SYNC_IO",      _PC_SYNC_IO},
9398
#endif
9399
#ifdef _PC_VDISABLE
9400
    {"PC_VDISABLE",     _PC_VDISABLE},
9401
#endif
9402
#ifdef _PC_ACL_ENABLED
9403
    {"PC_ACL_ENABLED",  _PC_ACL_ENABLED},
9404
#endif
9405
#ifdef _PC_MIN_HOLE_SIZE
9406
    {"PC_MIN_HOLE_SIZE",    _PC_MIN_HOLE_SIZE},
9407
#endif
9408
#ifdef _PC_ALLOC_SIZE_MIN
9409
    {"PC_ALLOC_SIZE_MIN",   _PC_ALLOC_SIZE_MIN},
9410
#endif
9411
#ifdef _PC_REC_INCR_XFER_SIZE
9412
    {"PC_REC_INCR_XFER_SIZE",   _PC_REC_INCR_XFER_SIZE},
9413
#endif
9414
#ifdef _PC_REC_MAX_XFER_SIZE
9415
    {"PC_REC_MAX_XFER_SIZE",    _PC_REC_MAX_XFER_SIZE},
9416
#endif
9417
#ifdef _PC_REC_MIN_XFER_SIZE
9418
    {"PC_REC_MIN_XFER_SIZE",    _PC_REC_MIN_XFER_SIZE},
9419
#endif
9420
#ifdef _PC_REC_XFER_ALIGN
9421
    {"PC_REC_XFER_ALIGN",   _PC_REC_XFER_ALIGN},
9422
#endif
9423
#ifdef _PC_SYMLINK_MAX
9424
    {"PC_SYMLINK_MAX",  _PC_SYMLINK_MAX},
9425
#endif
9426
#ifdef _PC_XATTR_ENABLED
9427
    {"PC_XATTR_ENABLED",    _PC_XATTR_ENABLED},
9428
#endif
9429
#ifdef _PC_XATTR_EXISTS
9430
    {"PC_XATTR_EXISTS", _PC_XATTR_EXISTS},
9431
#endif
9432
#ifdef _PC_TIMESTAMP_RESOLUTION
9433
    {"PC_TIMESTAMP_RESOLUTION", _PC_TIMESTAMP_RESOLUTION},
9434
#endif
9435
};
9436

9437
static int
9438
conv_path_confname(PyObject *arg, int *valuep)
9439
{
9440
    return conv_confname(arg, valuep, posix_constants_pathconf,
inline
           
conv_confname too costly to inline (cost=335, threshold=250) 
conv_path_confname
inline
           
conv_confname will not be inlined into conv_path_confname 
conv_path_confname
9441
                         sizeof(posix_constants_pathconf)
9442
                           / sizeof(struct constdef));
9443
}
9444
#endif
9445

9446

9447
#ifdef HAVE_FPATHCONF
9448
/*[clinic input]
9449
os.fpathconf -> long
9450

9451
    fd: int
9452
    name: path_confname
9453
    /
9454

9455
Return the configuration limit name for the file descriptor fd.
9456

9457
If there is no limit, return -1.
9458
[clinic start generated code]*/
9459

9460
static long
9461
os_fpathconf_impl(PyObject *module, int fd, int name)
9462
/*[clinic end generated code: output=d5b7042425fc3e21 input=5942a024d3777810]*/
9463
{
9464
    long limit;
9465

9466
    errno = 0;
inline
    
__errno_location will not be inlined into os_fpathconf_impl because its definition is unavailable 
os_fpathconf_impl
9467
    limit = fpathconf(fd, name);
inline
            
fpathconf will not be inlined into os_fpathconf_impl because its definition is unavailable 
os_fpathconf_impl
9468
    if (limit == -1 && errno != 0)
gvn
                       
load of type i32 not eliminated in favor of store because it is clobbered by call 
os_fpathconf_impl
gvn
                       
load of type i32 not eliminated in favor of store because it is clobbered by call 
os_fpathconf
9469
        posix_error();
inline
        
posix_error can be inlined into os_fpathconf_impl with cost=10 (threshold=375) 
os_fpathconf_impl
inline
        
posix_error inlined into os_fpathconf_impl 
os_fpathconf_impl
9470

9471
    return limit;
9472
}
9473
#endif /* HAVE_FPATHCONF */
9474

9475

9476
#ifdef HAVE_PATHCONF
9477
/*[clinic input]
9478
os.pathconf -> long
9479
    path: path_t(allow_fd='PATH_HAVE_FPATHCONF')
9480
    name: path_confname
9481

9482
Return the configuration limit name for the file or directory path.
9483

9484
If there is no limit, return -1.
9485
On some platforms, path may also be specified as an open file descriptor.
9486
  If this functionality is unavailable, using it raises an exception.
9487
[clinic start generated code]*/
9488

9489
static long
9490
os_pathconf_impl(PyObject *module, path_t *path, int name)
9491
/*[clinic end generated code: output=5bedee35b293a089 input=bc3e2a985af27e5e]*/
9492
{
9493
    long limit;
9494

9495
    errno = 0;
inline
    
__errno_location will not be inlined into os_pathconf_impl because its definition is unavailable 
os_pathconf_impl
9496
#ifdef HAVE_FPATHCONF
9497
    if (path->fd != -1)
gvn
              
load of type i32 not eliminated because it is clobbered by store 
os_pathconf_impl
gvn
              
load of type i32 not eliminated in favor of store because it is clobbered by store 
os_pathconf
9498
        limit = fpathconf(path->fd, name);
inline
                
fpathconf will not be inlined into os_pathconf_impl because its definition is unavailable 
os_pathconf_impl
9499
    else
9500
#endif
9501
        limit = pathconf(path->narrow, name);
inline
                
pathconf will not be inlined into os_pathconf_impl because its definition is unavailable 
os_pathconf_impl
gvn
                               
load of type i8* not eliminated because it is clobbered by call 
os_pathconf
9502
    if (limit == -1 && errno != 0) {
gvn
                       
load of type i32 not eliminated in favor of store because it is clobbered by call 
os_pathconf_impl
gvn
                       
load of type i32 not eliminated in favor of store because it is clobbered by call 
os_pathconf
9503
        if (errno == EINVAL)
9504
            /* could be a path or name problem */
9505
            posix_error();
inline
            
posix_error can be inlined into os_pathconf_impl with cost=10 (threshold=375) 
os_pathconf_impl
inline
            
posix_error inlined into os_pathconf_impl 
os_pathconf_impl
9506
        else
9507
            path_error(path);
inline
            
path_error can be inlined into os_pathconf_impl with cost=10 (threshold=375) 
os_pathconf_impl
inline
            
path_error inlined into os_pathconf_impl 
os_pathconf_impl
9508
    }
9509

9510
    return limit;
9511
}
9512
#endif /* HAVE_PATHCONF */
9513

9514
#ifdef HAVE_CONFSTR
9515
static struct constdef posix_constants_confstr[] = {
9516
#ifdef _CS_ARCHITECTURE
9517
    {"CS_ARCHITECTURE", _CS_ARCHITECTURE},
9518
#endif
9519
#ifdef _CS_GNU_LIBC_VERSION
9520
    {"CS_GNU_LIBC_VERSION",     _CS_GNU_LIBC_VERSION},
9521
#endif
9522
#ifdef _CS_GNU_LIBPTHREAD_VERSION
9523
    {"CS_GNU_LIBPTHREAD_VERSION",       _CS_GNU_LIBPTHREAD_VERSION},
9524
#endif
9525
#ifdef _CS_HOSTNAME
9526
    {"CS_HOSTNAME",     _CS_HOSTNAME},
9527
#endif
9528
#ifdef _CS_HW_PROVIDER
9529
    {"CS_HW_PROVIDER",  _CS_HW_PROVIDER},
9530
#endif
9531
#ifdef _CS_HW_SERIAL
9532
    {"CS_HW_SERIAL",    _CS_HW_SERIAL},
9533
#endif
9534
#ifdef _CS_INITTAB_NAME
9535
    {"CS_INITTAB_NAME", _CS_INITTAB_NAME},
9536
#endif
9537
#ifdef _CS_LFS64_CFLAGS
9538
    {"CS_LFS64_CFLAGS", _CS_LFS64_CFLAGS},
9539
#endif
9540
#ifdef _CS_LFS64_LDFLAGS
9541
    {"CS_LFS64_LDFLAGS",        _CS_LFS64_LDFLAGS},
9542
#endif
9543
#ifdef _CS_LFS64_LIBS
9544
    {"CS_LFS64_LIBS",   _CS_LFS64_LIBS},
9545
#endif
9546
#ifdef _CS_LFS64_LINTFLAGS
9547
    {"CS_LFS64_LINTFLAGS",      _CS_LFS64_LINTFLAGS},
9548
#endif
9549
#ifdef _CS_LFS_CFLAGS
9550
    {"CS_LFS_CFLAGS",   _CS_LFS_CFLAGS},
9551
#endif
9552
#ifdef _CS_LFS_LDFLAGS
9553
    {"CS_LFS_LDFLAGS",  _CS_LFS_LDFLAGS},
9554
#endif
9555
#ifdef _CS_LFS_LIBS
9556
    {"CS_LFS_LIBS",     _CS_LFS_LIBS},
9557
#endif
9558
#ifdef _CS_LFS_LINTFLAGS
9559
    {"CS_LFS_LINTFLAGS",        _CS_LFS_LINTFLAGS},
9560
#endif
9561
#ifdef _CS_MACHINE
9562
    {"CS_MACHINE",      _CS_MACHINE},
9563
#endif
9564
#ifdef _CS_PATH
9565
    {"CS_PATH", _CS_PATH},
9566
#endif
9567
#ifdef _CS_RELEASE
9568
    {"CS_RELEASE",      _CS_RELEASE},
9569
#endif
9570
#ifdef _CS_SRPC_DOMAIN
9571
    {"CS_SRPC_DOMAIN",  _CS_SRPC_DOMAIN},
9572
#endif
9573
#ifdef _CS_SYSNAME
9574
    {"CS_SYSNAME",      _CS_SYSNAME},
9575
#endif
9576
#ifdef _CS_VERSION
9577
    {"CS_VERSION",      _CS_VERSION},
9578
#endif
9579
#ifdef _CS_XBS5_ILP32_OFF32_CFLAGS
9580
    {"CS_XBS5_ILP32_OFF32_CFLAGS",      _CS_XBS5_ILP32_OFF32_CFLAGS},
9581
#endif
9582
#ifdef _CS_XBS5_ILP32_OFF32_LDFLAGS
9583
    {"CS_XBS5_ILP32_OFF32_LDFLAGS",     _CS_XBS5_ILP32_OFF32_LDFLAGS},
9584
#endif
9585
#ifdef _CS_XBS5_ILP32_OFF32_LIBS
9586
    {"CS_XBS5_ILP32_OFF32_LIBS",        _CS_XBS5_ILP32_OFF32_LIBS},
9587
#endif
9588
#ifdef _CS_XBS5_ILP32_OFF32_LINTFLAGS
9589
    {"CS_XBS5_ILP32_OFF32_LINTFLAGS",   _CS_XBS5_ILP32_OFF32_LINTFLAGS},
9590
#endif
9591
#ifdef _CS_XBS5_ILP32_OFFBIG_CFLAGS
9592
    {"CS_XBS5_ILP32_OFFBIG_CFLAGS",     _CS_XBS5_ILP32_OFFBIG_CFLAGS},
9593
#endif
9594
#ifdef _CS_XBS5_ILP32_OFFBIG_LDFLAGS
9595
    {"CS_XBS5_ILP32_OFFBIG_LDFLAGS",    _CS_XBS5_ILP32_OFFBIG_LDFLAGS},
9596
#endif
9597
#ifdef _CS_XBS5_ILP32_OFFBIG_LIBS
9598
    {"CS_XBS5_ILP32_OFFBIG_LIBS",       _CS_XBS5_ILP32_OFFBIG_LIBS},
9599
#endif
9600
#ifdef _CS_XBS5_ILP32_OFFBIG_LINTFLAGS
9601
    {"CS_XBS5_ILP32_OFFBIG_LINTFLAGS",  _CS_XBS5_ILP32_OFFBIG_LINTFLAGS},
9602
#endif
9603
#ifdef _CS_XBS5_LP64_OFF64_CFLAGS
9604
    {"CS_XBS5_LP64_OFF64_CFLAGS",       _CS_XBS5_LP64_OFF64_CFLAGS},
9605
#endif
9606
#ifdef _CS_XBS5_LP64_OFF64_LDFLAGS
9607
    {"CS_XBS5_LP64_OFF64_LDFLAGS",      _CS_XBS5_LP64_OFF64_LDFLAGS},
9608
#endif
9609
#ifdef _CS_XBS5_LP64_OFF64_LIBS
9610
    {"CS_XBS5_LP64_OFF64_LIBS", _CS_XBS5_LP64_OFF64_LIBS},
9611
#endif
9612
#ifdef _CS_XBS5_LP64_OFF64_LINTFLAGS
9613
    {"CS_XBS5_LP64_OFF64_LINTFLAGS",    _CS_XBS5_LP64_OFF64_LINTFLAGS},
9614
#endif
9615
#ifdef _CS_XBS5_LPBIG_OFFBIG_CFLAGS
9616
    {"CS_XBS5_LPBIG_OFFBIG_CFLAGS",     _CS_XBS5_LPBIG_OFFBIG_CFLAGS},
9617
#endif
9618
#ifdef _CS_XBS5_LPBIG_OFFBIG_LDFLAGS
9619
    {"CS_XBS5_LPBIG_OFFBIG_LDFLAGS",    _CS_XBS5_LPBIG_OFFBIG_LDFLAGS},
9620
#endif
9621
#ifdef _CS_XBS5_LPBIG_OFFBIG_LIBS
9622
    {"CS_XBS5_LPBIG_OFFBIG_LIBS",       _CS_XBS5_LPBIG_OFFBIG_LIBS},
9623
#endif
9624
#ifdef _CS_XBS5_LPBIG_OFFBIG_LINTFLAGS
9625
    {"CS_XBS5_LPBIG_OFFBIG_LINTFLAGS",  _CS_XBS5_LPBIG_OFFBIG_LINTFLAGS},
9626
#endif
9627
#ifdef _MIPS_CS_AVAIL_PROCESSORS
9628
    {"MIPS_CS_AVAIL_PROCESSORS",        _MIPS_CS_AVAIL_PROCESSORS},
9629
#endif
9630
#ifdef _MIPS_CS_BASE
9631
    {"MIPS_CS_BASE",    _MIPS_CS_BASE},
9632
#endif
9633
#ifdef _MIPS_CS_HOSTID
9634
    {"MIPS_CS_HOSTID",  _MIPS_CS_HOSTID},
9635
#endif
9636
#ifdef _MIPS_CS_HW_NAME
9637
    {"MIPS_CS_HW_NAME", _MIPS_CS_HW_NAME},
9638
#endif
9639
#ifdef _MIPS_CS_NUM_PROCESSORS
9640
    {"MIPS_CS_NUM_PROCESSORS",  _MIPS_CS_NUM_PROCESSORS},
9641
#endif
9642
#ifdef _MIPS_CS_OSREL_MAJ
9643
    {"MIPS_CS_OSREL_MAJ",       _MIPS_CS_OSREL_MAJ},
9644
#endif
9645
#ifdef _MIPS_CS_OSREL_MIN
9646
    {"MIPS_CS_OSREL_MIN",       _MIPS_CS_OSREL_MIN},
9647
#endif
9648
#ifdef _MIPS_CS_OSREL_PATCH
9649
    {"MIPS_CS_OSREL_PATCH",     _MIPS_CS_OSREL_PATCH},
9650
#endif
9651
#ifdef _MIPS_CS_OS_NAME
9652
    {"MIPS_CS_OS_NAME", _MIPS_CS_OS_NAME},
9653
#endif
9654
#ifdef _MIPS_CS_OS_PROVIDER
9655
    {"MIPS_CS_OS_PROVIDER",     _MIPS_CS_OS_PROVIDER},
9656
#endif
9657
#ifdef _MIPS_CS_PROCESSORS
9658
    {"MIPS_CS_PROCESSORS",      _MIPS_CS_PROCESSORS},
9659
#endif
9660
#ifdef _MIPS_CS_SERIAL
9661
    {"MIPS_CS_SERIAL",  _MIPS_CS_SERIAL},
9662
#endif
9663
#ifdef _MIPS_CS_VENDOR
9664
    {"MIPS_CS_VENDOR",  _MIPS_CS_VENDOR},
9665
#endif
9666
};
9667

9668
static int
9669
conv_confstr_confname(PyObject *arg, int *valuep)
9670
{
9671
    return conv_confname(arg, valuep, posix_constants_confstr,
inline
           
conv_confname too costly to inline (cost=335, threshold=250) 
conv_confstr_confname
inline
           
conv_confname will not be inlined into conv_confstr_confname 
conv_confstr_confname
9672
                         sizeof(posix_constants_confstr)
9673
                           / sizeof(struct constdef));
9674
}
9675

9676

9677
/*[clinic input]
9678
os.confstr
9679

9680
    name: confstr_confname
9681
    /
9682

9683
Return a string-valued system configuration variable.
9684
[clinic start generated code]*/
9685

9686
static PyObject *
9687
os_confstr_impl(PyObject *module, int name)
9688
/*[clinic end generated code: output=bfb0b1b1e49b9383 input=18fb4d0567242e65]*/
9689
{
9690
    PyObject *result = NULL;
9691
    char buffer[255];
9692
    size_t len;
9693

9694
    errno = 0;
inline
    
__errno_location will not be inlined into os_confstr_impl because its definition is unavailable 
os_confstr_impl
9695
    len = confstr(name, buffer, sizeof(buffer));
inline
          
confstr will not be inlined into os_confstr_impl because its definition is unavailable 
os_confstr_impl
9696
    if (len == 0) {
9697
        if (errno) {
gvn
            
load of type i32 not eliminated in favor of store because it is clobbered by call 
os_confstr_impl
gvn
            
load of type i32 not eliminated in favor of store because it is clobbered by call 
os_confstr
9698
            posix_error();
inline
            
posix_error can be inlined into os_confstr_impl with cost=10 (threshold=375) 
os_confstr_impl
inline
            
posix_error inlined into os_confstr_impl 
os_confstr_impl
9699
            return NULL;
9700
        }
9701
        else {
9702
            Py_RETURN_NONE;
gvn
            
load of type i64 not eliminated because it is clobbered by call 
os_confstr_impl
gvn
            
load of type i64 not eliminated because it is clobbered by call 
os_confstr
9703
        }
9704
    }
9705

9706
    if (len >= sizeof(buffer)) {
9707
        size_t len2;
9708
        char *buf = PyMem_Malloc(len);
inline
                    
PyMem_Malloc will not be inlined into os_confstr_impl because its definition is unavailable 
os_confstr_impl
9709
        if (buf == NULL)
9710
            return PyErr_NoMemory();
inline
                   
PyErr_NoMemory will not be inlined into os_confstr_impl because its definition is unavailable 
os_confstr_impl
9711
        len2 = confstr(name, buf, len);
inline
               
confstr will not be inlined into os_confstr_impl because its definition is unavailable 
os_confstr_impl
9712
        assert(len == len2);
9713
        result = PyUnicode_DecodeFSDefaultAndSize(buf, len2-1);
inline
                 
PyUnicode_DecodeFSDefaultAndSize will not be inlined into os_confstr_impl because its definition is unavailable 
os_confstr_impl
9714
        PyMem_Free(buf);
inline
        
PyMem_Free will not be inlined into os_confstr_impl because its definition is unavailable 
os_confstr_impl
9715
    }
9716
    else
9717
        result = PyUnicode_DecodeFSDefaultAndSize(buffer, len-1);
inline
                 
PyUnicode_DecodeFSDefaultAndSize will not be inlined into os_confstr_impl because its definition is unavailable 
os_confstr_impl
9718
    return result;
9719
}
9720
#endif /* HAVE_CONFSTR */
9721

9722

9723
#ifdef HAVE_SYSCONF
9724
static struct constdef posix_constants_sysconf[] = {
9725
#ifdef _SC_2_CHAR_TERM
9726
    {"SC_2_CHAR_TERM",  _SC_2_CHAR_TERM},
9727
#endif
9728
#ifdef _SC_2_C_BIND
9729
    {"SC_2_C_BIND",     _SC_2_C_BIND},
9730
#endif
9731
#ifdef _SC_2_C_DEV
9732
    {"SC_2_C_DEV",      _SC_2_C_DEV},
9733
#endif
9734
#ifdef _SC_2_C_VERSION
9735
    {"SC_2_C_VERSION",  _SC_2_C_VERSION},
9736
#endif
9737
#ifdef _SC_2_FORT_DEV
9738
    {"SC_2_FORT_DEV",   _SC_2_FORT_DEV},
9739
#endif
9740
#ifdef _SC_2_FORT_RUN
9741
    {"SC_2_FORT_RUN",   _SC_2_FORT_RUN},
9742
#endif
9743
#ifdef _SC_2_LOCALEDEF
9744
    {"SC_2_LOCALEDEF",  _SC_2_LOCALEDEF},
9745
#endif
9746
#ifdef _SC_2_SW_DEV
9747
    {"SC_2_SW_DEV",     _SC_2_SW_DEV},
9748
#endif
9749
#ifdef _SC_2_UPE
9750
    {"SC_2_UPE",        _SC_2_UPE},
9751
#endif
9752
#ifdef _SC_2_VERSION
9753
    {"SC_2_VERSION",    _SC_2_VERSION},
9754
#endif
9755
#ifdef _SC_ABI_ASYNCHRONOUS_IO
9756
    {"SC_ABI_ASYNCHRONOUS_IO",  _SC_ABI_ASYNCHRONOUS_IO},
9757
#endif
9758
#ifdef _SC_ACL
9759
    {"SC_ACL",  _SC_ACL},
9760
#endif
9761
#ifdef _SC_AIO_LISTIO_MAX
9762
    {"SC_AIO_LISTIO_MAX",       _SC_AIO_LISTIO_MAX},
9763
#endif
9764
#ifdef _SC_AIO_MAX
9765
    {"SC_AIO_MAX",      _SC_AIO_MAX},
9766
#endif
9767
#ifdef _SC_AIO_PRIO_DELTA_MAX
9768
    {"SC_AIO_PRIO_DELTA_MAX",   _SC_AIO_PRIO_DELTA_MAX},
9769
#endif
9770
#ifdef _SC_ARG_MAX
9771
    {"SC_ARG_MAX",      _SC_ARG_MAX},
9772
#endif
9773
#ifdef _SC_ASYNCHRONOUS_IO
9774
    {"SC_ASYNCHRONOUS_IO",      _SC_ASYNCHRONOUS_IO},
9775
#endif
9776
#ifdef _SC_ATEXIT_MAX
9777
    {"SC_ATEXIT_MAX",   _SC_ATEXIT_MAX},
9778
#endif
9779
#ifdef _SC_AUDIT
9780
    {"SC_AUDIT",        _SC_AUDIT},
9781
#endif
9782
#ifdef _SC_AVPHYS_PAGES
9783
    {"SC_AVPHYS_PAGES", _SC_AVPHYS_PAGES},
9784
#endif
9785
#ifdef _SC_BC_BASE_MAX
9786
    {"SC_BC_BASE_MAX",  _SC_BC_BASE_MAX},
9787
#endif
9788
#ifdef _SC_BC_DIM_MAX
9789
    {"SC_BC_DIM_MAX",   _SC_BC_DIM_MAX},
9790
#endif
9791
#ifdef _SC_BC_SCALE_MAX
9792
    {"SC_BC_SCALE_MAX", _SC_BC_SCALE_MAX},
9793
#endif
9794
#ifdef _SC_BC_STRING_MAX
9795
    {"SC_BC_STRING_MAX",        _SC_BC_STRING_MAX},
9796
#endif
9797
#ifdef _SC_CAP
9798
    {"SC_CAP",  _SC_CAP},
9799
#endif
9800
#ifdef _SC_CHARCLASS_NAME_MAX
9801
    {"SC_CHARCLASS_NAME_MAX",   _SC_CHARCLASS_NAME_MAX},
9802
#endif
9803
#ifdef _SC_CHAR_BIT
9804
    {"SC_CHAR_BIT",     _SC_CHAR_BIT},
9805
#endif
9806
#ifdef _SC_CHAR_MAX
9807
    {"SC_CHAR_MAX",     _SC_CHAR_MAX},
9808
#endif
9809
#ifdef _SC_CHAR_MIN
9810
    {"SC_CHAR_MIN",     _SC_CHAR_MIN},
9811
#endif
9812
#ifdef _SC_CHILD_MAX
9813
    {"SC_CHILD_MAX",    _SC_CHILD_MAX},
9814
#endif
9815
#ifdef _SC_CLK_TCK
9816
    {"SC_CLK_TCK",      _SC_CLK_TCK},
9817
#endif
9818
#ifdef _SC_COHER_BLKSZ
9819
    {"SC_COHER_BLKSZ",  _SC_COHER_BLKSZ},
9820
#endif
9821
#ifdef _SC_COLL_WEIGHTS_MAX
9822
    {"SC_COLL_WEIGHTS_MAX",     _SC_COLL_WEIGHTS_MAX},
9823
#endif
9824
#ifdef _SC_DCACHE_ASSOC
9825
    {"SC_DCACHE_ASSOC", _SC_DCACHE_ASSOC},
9826
#endif
9827
#ifdef _SC_DCACHE_BLKSZ
9828
    {"SC_DCACHE_BLKSZ", _SC_DCACHE_BLKSZ},
9829
#endif
9830
#ifdef _SC_DCACHE_LINESZ
9831
    {"SC_DCACHE_LINESZ",        _SC_DCACHE_LINESZ},
9832
#endif
9833
#ifdef _SC_DCACHE_SZ
9834
    {"SC_DCACHE_SZ",    _SC_DCACHE_SZ},
9835
#endif
9836
#ifdef _SC_DCACHE_TBLKSZ
9837
    {"SC_DCACHE_TBLKSZ",        _SC_DCACHE_TBLKSZ},
9838
#endif
9839
#ifdef _SC_DELAYTIMER_MAX
9840
    {"SC_DELAYTIMER_MAX",       _SC_DELAYTIMER_MAX},
9841
#endif
9842
#ifdef _SC_EQUIV_CLASS_MAX
9843
    {"SC_EQUIV_CLASS_MAX",      _SC_EQUIV_CLASS_MAX},
9844
#endif
9845
#ifdef _SC_EXPR_NEST_MAX
9846
    {"SC_EXPR_NEST_MAX",        _SC_EXPR_NEST_MAX},
9847
#endif
9848
#ifdef _SC_FSYNC
9849
    {"SC_FSYNC",        _SC_FSYNC},
9850
#endif
9851
#ifdef _SC_GETGR_R_SIZE_MAX
9852
    {"SC_GETGR_R_SIZE_MAX",     _SC_GETGR_R_SIZE_MAX},
9853
#endif
9854
#ifdef _SC_GETPW_R_SIZE_MAX
9855
    {"SC_GETPW_R_SIZE_MAX",     _SC_GETPW_R_SIZE_MAX},
9856
#endif
9857
#ifdef _SC_ICACHE_ASSOC
9858
    {"SC_ICACHE_ASSOC", _SC_ICACHE_ASSOC},
9859
#endif
9860
#ifdef _SC_ICACHE_BLKSZ
9861
    {"SC_ICACHE_BLKSZ", _SC_ICACHE_BLKSZ},
9862
#endif
9863
#ifdef _SC_ICACHE_LINESZ
9864
    {"SC_ICACHE_LINESZ",        _SC_ICACHE_LINESZ},
9865
#endif
9866
#ifdef _SC_ICACHE_SZ
9867
    {"SC_ICACHE_SZ",    _SC_ICACHE_SZ},
9868
#endif
9869
#ifdef _SC_INF
9870
    {"SC_INF",  _SC_INF},
9871
#endif
9872
#ifdef _SC_INT_MAX
9873
    {"SC_INT_MAX",      _SC_INT_MAX},
9874
#endif
9875
#ifdef _SC_INT_MIN
9876
    {"SC_INT_MIN",      _SC_INT_MIN},
9877
#endif
9878
#ifdef _SC_IOV_MAX
9879
    {"SC_IOV_MAX",      _SC_IOV_MAX},
9880
#endif
9881
#ifdef _SC_IP_SECOPTS
9882
    {"SC_IP_SECOPTS",   _SC_IP_SECOPTS},
9883
#endif
9884
#ifdef _SC_JOB_CONTROL
9885
    {"SC_JOB_CONTROL",  _SC_JOB_CONTROL},
9886
#endif
9887
#ifdef _SC_KERN_POINTERS
9888
    {"SC_KERN_POINTERS",        _SC_KERN_POINTERS},
9889
#endif
9890
#ifdef _SC_KERN_SIM
9891
    {"SC_KERN_SIM",     _SC_KERN_SIM},
9892
#endif
9893
#ifdef _SC_LINE_MAX
9894
    {"SC_LINE_MAX",     _SC_LINE_MAX},
9895
#endif
9896
#ifdef _SC_LOGIN_NAME_MAX
9897
    {"SC_LOGIN_NAME_MAX",       _SC_LOGIN_NAME_MAX},
9898
#endif
9899
#ifdef _SC_LOGNAME_MAX
9900
    {"SC_LOGNAME_MAX",  _SC_LOGNAME_MAX},
9901
#endif
9902
#ifdef _SC_LONG_BIT
9903
    {"SC_LONG_BIT",     _SC_LONG_BIT},
9904
#endif
9905
#ifdef _SC_MAC
9906
    {"SC_MAC",  _SC_MAC},
9907
#endif
9908
#ifdef _SC_MAPPED_FILES
9909
    {"SC_MAPPED_FILES", _SC_MAPPED_FILES},
9910
#endif
9911
#ifdef _SC_MAXPID
9912
    {"SC_MAXPID",       _SC_MAXPID},
9913
#endif
9914
#ifdef _SC_MB_LEN_MAX
9915
    {"SC_MB_LEN_MAX",   _SC_MB_LEN_MAX},
9916
#endif
9917
#ifdef _SC_MEMLOCK
9918
    {"SC_MEMLOCK",      _SC_MEMLOCK},
9919
#endif
9920
#ifdef _SC_MEMLOCK_RANGE
9921
    {"SC_MEMLOCK_RANGE",        _SC_MEMLOCK_RANGE},
9922
#endif
9923
#ifdef _SC_MEMORY_PROTECTION
9924
    {"SC_MEMORY_PROTECTION",    _SC_MEMORY_PROTECTION},
9925
#endif
9926
#ifdef _SC_MESSAGE_PASSING
9927
    {"SC_MESSAGE_PASSING",      _SC_MESSAGE_PASSING},
9928
#endif
9929
#ifdef _SC_MMAP_FIXED_ALIGNMENT
9930
    {"SC_MMAP_FIXED_ALIGNMENT", _SC_MMAP_FIXED_ALIGNMENT},
9931
#endif
9932
#ifdef _SC_MQ_OPEN_MAX
9933
    {"SC_MQ_OPEN_MAX",  _SC_MQ_OPEN_MAX},
9934
#endif
9935
#ifdef _SC_MQ_PRIO_MAX
9936
    {"SC_MQ_PRIO_MAX",  _SC_MQ_PRIO_MAX},
9937
#endif
9938
#ifdef _SC_NACLS_MAX
9939
    {"SC_NACLS_MAX",    _SC_NACLS_MAX},
9940
#endif
9941
#ifdef _SC_NGROUPS_MAX
9942
    {"SC_NGROUPS_MAX",  _SC_NGROUPS_MAX},
9943
#endif
9944
#ifdef _SC_NL_ARGMAX
9945
    {"SC_NL_ARGMAX",    _SC_NL_ARGMAX},
9946
#endif
9947
#ifdef _SC_NL_LANGMAX
9948
    {"SC_NL_LANGMAX",   _SC_NL_LANGMAX},
9949
#endif
9950
#ifdef _SC_NL_MSGMAX
9951
    {"SC_NL_MSGMAX",    _SC_NL_MSGMAX},
9952
#endif
9953
#ifdef _SC_NL_NMAX
9954
    {"SC_NL_NMAX",      _SC_NL_NMAX},
9955
#endif
9956
#ifdef _SC_NL_SETMAX
9957
    {"SC_NL_SETMAX",    _SC_NL_SETMAX},
9958
#endif
9959
#ifdef _SC_NL_TEXTMAX
9960
    {"SC_NL_TEXTMAX",   _SC_NL_TEXTMAX},
9961
#endif
9962
#ifdef _SC_NPROCESSORS_CONF
9963
    {"SC_NPROCESSORS_CONF",     _SC_NPROCESSORS_CONF},
9964
#endif
9965
#ifdef _SC_NPROCESSORS_ONLN
9966
    {"SC_NPROCESSORS_ONLN",     _SC_NPROCESSORS_ONLN},
9967
#endif
9968
#ifdef _SC_NPROC_CONF
9969
    {"SC_NPROC_CONF",   _SC_NPROC_CONF},
9970
#endif
9971
#ifdef _SC_NPROC_ONLN
9972
    {"SC_NPROC_ONLN",   _SC_NPROC_ONLN},
9973
#endif
9974
#ifdef _SC_NZERO
9975
    {"SC_NZERO",        _SC_NZERO},
9976
#endif
9977
#ifdef _SC_OPEN_MAX
9978
    {"SC_OPEN_MAX",     _SC_OPEN_MAX},
9979
#endif
9980
#ifdef _SC_PAGESIZE
9981
    {"SC_PAGESIZE",     _SC_PAGESIZE},
9982
#endif
9983
#ifdef _SC_PAGE_SIZE
9984
    {"SC_PAGE_SIZE",    _SC_PAGE_SIZE},
9985
#endif
9986
#ifdef _SC_PASS_MAX
9987
    {"SC_PASS_MAX",     _SC_PASS_MAX},
9988
#endif
9989
#ifdef _SC_PHYS_PAGES
9990
    {"SC_PHYS_PAGES",   _SC_PHYS_PAGES},
9991
#endif
9992
#ifdef _SC_PII
9993
    {"SC_PII",  _SC_PII},
9994
#endif
9995
#ifdef _SC_PII_INTERNET
9996
    {"SC_PII_INTERNET", _SC_PII_INTERNET},
9997
#endif
9998
#ifdef _SC_PII_INTERNET_DGRAM
9999
    {"SC_PII_INTERNET_DGRAM",   _SC_PII_INTERNET_DGRAM},
10000
#endif
10001
#ifdef _SC_PII_INTERNET_STREAM
10002
    {"SC_PII_INTERNET_STREAM",  _SC_PII_INTERNET_STREAM},
10003
#endif
10004
#ifdef _SC_PII_OSI
10005
    {"SC_PII_OSI",      _SC_PII_OSI},
10006
#endif
10007
#ifdef _SC_PII_OSI_CLTS
10008
    {"SC_PII_OSI_CLTS", _SC_PII_OSI_CLTS},
10009
#endif
10010
#ifdef _SC_PII_OSI_COTS
10011
    {"SC_PII_OSI_COTS", _SC_PII_OSI_COTS},
10012
#endif
10013
#ifdef _SC_PII_OSI_M
10014
    {"SC_PII_OSI_M",    _SC_PII_OSI_M},
10015
#endif
10016
#ifdef _SC_PII_SOCKET
10017
    {"SC_PII_SOCKET",   _SC_PII_SOCKET},
10018
#endif
10019
#ifdef _SC_PII_XTI
10020
    {"SC_PII_XTI",      _SC_PII_XTI},
10021
#endif
10022
#ifdef _SC_POLL
10023
    {"SC_POLL", _SC_POLL},
10024
#endif
10025
#ifdef _SC_PRIORITIZED_IO
10026
    {"SC_PRIORITIZED_IO",       _SC_PRIORITIZED_IO},
10027
#endif
10028
#ifdef _SC_PRIORITY_SCHEDULING
10029
    {"SC_PRIORITY_SCHEDULING",  _SC_PRIORITY_SCHEDULING},
10030
#endif
10031
#ifdef _SC_REALTIME_SIGNALS
10032
    {"SC_REALTIME_SIGNALS",     _SC_REALTIME_SIGNALS},
10033
#endif
10034
#ifdef _SC_RE_DUP_MAX
10035
    {"SC_RE_DUP_MAX",   _SC_RE_DUP_MAX},
10036
#endif
10037
#ifdef _SC_RTSIG_MAX
10038
    {"SC_RTSIG_MAX",    _SC_RTSIG_MAX},
10039
#endif
10040
#ifdef _SC_SAVED_IDS
10041
    {"SC_SAVED_IDS",    _SC_SAVED_IDS},
10042
#endif
10043
#ifdef _SC_SCHAR_MAX
10044
    {"SC_SCHAR_MAX",    _SC_SCHAR_MAX},
10045
#endif
10046
#ifdef _SC_SCHAR_MIN
10047
    {"SC_SCHAR_MIN",    _SC_SCHAR_MIN},
10048
#endif
10049
#ifdef _SC_SELECT
10050
    {"SC_SELECT",       _SC_SELECT},
10051
#endif
10052
#ifdef _SC_SEMAPHORES
10053
    {"SC_SEMAPHORES",   _SC_SEMAPHORES},
10054
#endif
10055
#ifdef _SC_SEM_NSEMS_MAX
10056
    {"SC_SEM_NSEMS_MAX",        _SC_SEM_NSEMS_MAX},
10057
#endif
10058
#ifdef _SC_SEM_VALUE_MAX
10059
    {"SC_SEM_VALUE_MAX",        _SC_SEM_VALUE_MAX},
10060
#endif
10061
#ifdef _SC_SHARED_MEMORY_OBJECTS
10062
    {"SC_SHARED_MEMORY_OBJECTS",        _SC_SHARED_MEMORY_OBJECTS},
10063
#endif
10064
#ifdef _SC_SHRT_MAX
10065
    {"SC_SHRT_MAX",     _SC_SHRT_MAX},
10066
#endif
10067
#ifdef _SC_SHRT_MIN
10068
    {"SC_SHRT_MIN",     _SC_SHRT_MIN},
10069
#endif
10070
#ifdef _SC_SIGQUEUE_MAX
10071
    {"SC_SIGQUEUE_MAX", _SC_SIGQUEUE_MAX},
10072
#endif
10073
#ifdef _SC_SIGRT_MAX
10074
    {"SC_SIGRT_MAX",    _SC_SIGRT_MAX},
10075
#endif
10076
#ifdef _SC_SIGRT_MIN
10077
    {"SC_SIGRT_MIN",    _SC_SIGRT_MIN},
10078
#endif
10079
#ifdef _SC_SOFTPOWER
10080
    {"SC_SOFTPOWER",    _SC_SOFTPOWER},
10081
#endif
10082
#ifdef _SC_SPLIT_CACHE
10083
    {"SC_SPLIT_CACHE",  _SC_SPLIT_CACHE},
10084
#endif
10085
#ifdef _SC_SSIZE_MAX
10086
    {"SC_SSIZE_MAX",    _SC_SSIZE_MAX},
10087
#endif
10088
#ifdef _SC_STACK_PROT
10089
    {"SC_STACK_PROT",   _SC_STACK_PROT},
10090
#endif
10091
#ifdef _SC_STREAM_MAX
10092
    {"SC_STREAM_MAX",   _SC_STREAM_MAX},
10093
#endif
10094
#ifdef _SC_SYNCHRONIZED_IO
10095
    {"SC_SYNCHRONIZED_IO",      _SC_SYNCHRONIZED_IO},
10096
#endif
10097
#ifdef _SC_THREADS
10098
    {"SC_THREADS",      _SC_THREADS},
10099
#endif
10100
#ifdef _SC_THREAD_ATTR_STACKADDR
10101
    {"SC_THREAD_ATTR_STACKADDR",        _SC_THREAD_ATTR_STACKADDR},
10102
#endif
10103
#ifdef _SC_THREAD_ATTR_STACKSIZE
10104
    {"SC_THREAD_ATTR_STACKSIZE",        _SC_THREAD_ATTR_STACKSIZE},
10105
#endif
10106
#ifdef _SC_THREAD_DESTRUCTOR_ITERATIONS
10107
    {"SC_THREAD_DESTRUCTOR_ITERATIONS", _SC_THREAD_DESTRUCTOR_ITERATIONS},
10108
#endif
10109
#ifdef _SC_THREAD_KEYS_MAX
10110
    {"SC_THREAD_KEYS_MAX",      _SC_THREAD_KEYS_MAX},
10111
#endif
10112
#ifdef _SC_THREAD_PRIORITY_SCHEDULING
10113
    {"SC_THREAD_PRIORITY_SCHEDULING",   _SC_THREAD_PRIORITY_SCHEDULING},
10114
#endif
10115
#ifdef _SC_THREAD_PRIO_INHERIT
10116
    {"SC_THREAD_PRIO_INHERIT",  _SC_THREAD_PRIO_INHERIT},
10117
#endif
10118
#ifdef _SC_THREAD_PRIO_PROTECT
10119
    {"SC_THREAD_PRIO_PROTECT",  _SC_THREAD_PRIO_PROTECT},
10120
#endif
10121
#ifdef _SC_THREAD_PROCESS_SHARED
10122
    {"SC_THREAD_PROCESS_SHARED",        _SC_THREAD_PROCESS_SHARED},
10123
#endif
10124
#ifdef _SC_THREAD_SAFE_FUNCTIONS
10125
    {"SC_THREAD_SAFE_FUNCTIONS",        _SC_THREAD_SAFE_FUNCTIONS},
10126
#endif
10127
#ifdef _SC_THREAD_STACK_MIN
10128
    {"SC_THREAD_STACK_MIN",     _SC_THREAD_STACK_MIN},
10129
#endif
10130
#ifdef _SC_THREAD_THREADS_MAX
10131
    {"SC_THREAD_THREADS_MAX",   _SC_THREAD_THREADS_MAX},
10132
#endif
10133
#ifdef _SC_TIMERS
10134
    {"SC_TIMERS",       _SC_TIMERS},
10135
#endif
10136
#ifdef _SC_TIMER_MAX
10137
    {"SC_TIMER_MAX",    _SC_TIMER_MAX},
10138
#endif
10139
#ifdef _SC_TTY_NAME_MAX
10140
    {"SC_TTY_NAME_MAX", _SC_TTY_NAME_MAX},
10141
#endif
10142
#ifdef _SC_TZNAME_MAX
10143
    {"SC_TZNAME_MAX",   _SC_TZNAME_MAX},
10144
#endif
10145
#ifdef _SC_T_IOV_MAX
10146
    {"SC_T_IOV_MAX",    _SC_T_IOV_MAX},
10147
#endif
10148
#ifdef _SC_UCHAR_MAX
10149
    {"SC_UCHAR_MAX",    _SC_UCHAR_MAX},
10150
#endif
10151
#ifdef _SC_UINT_MAX
10152
    {"SC_UINT_MAX",     _SC_UINT_MAX},
10153
#endif
10154
#ifdef _SC_UIO_MAXIOV
10155
    {"SC_UIO_MAXIOV",   _SC_UIO_MAXIOV},
10156
#endif
10157
#ifdef _SC_ULONG_MAX
10158
    {"SC_ULONG_MAX",    _SC_ULONG_MAX},
10159
#endif
10160
#ifdef _SC_USHRT_MAX
10161
    {"SC_USHRT_MAX",    _SC_USHRT_MAX},
10162
#endif
10163
#ifdef _SC_VERSION
10164
    {"SC_VERSION",      _SC_VERSION},
10165
#endif
10166
#ifdef _SC_WORD_BIT
10167
    {"SC_WORD_BIT",     _SC_WORD_BIT},
10168
#endif
10169
#ifdef _SC_XBS5_ILP32_OFF32
10170
    {"SC_XBS5_ILP32_OFF32",     _SC_XBS5_ILP32_OFF32},
10171
#endif
10172
#ifdef _SC_XBS5_ILP32_OFFBIG
10173
    {"SC_XBS5_ILP32_OFFBIG",    _SC_XBS5_ILP32_OFFBIG},
10174
#endif
10175
#ifdef _SC_XBS5_LP64_OFF64
10176
    {"SC_XBS5_LP64_OFF64",      _SC_XBS5_LP64_OFF64},
10177
#endif
10178
#ifdef _SC_XBS5_LPBIG_OFFBIG
10179
    {"SC_XBS5_LPBIG_OFFBIG",    _SC_XBS5_LPBIG_OFFBIG},
10180
#endif
10181
#ifdef _SC_XOPEN_CRYPT
10182
    {"SC_XOPEN_CRYPT",  _SC_XOPEN_CRYPT},
10183
#endif
10184
#ifdef _SC_XOPEN_ENH_I18N
10185
    {"SC_XOPEN_ENH_I18N",       _SC_XOPEN_ENH_I18N},
10186
#endif
10187
#ifdef _SC_XOPEN_LEGACY
10188
    {"SC_XOPEN_LEGACY", _SC_XOPEN_LEGACY},
10189
#endif
10190
#ifdef _SC_XOPEN_REALTIME
10191
    {"SC_XOPEN_REALTIME",       _SC_XOPEN_REALTIME},
10192
#endif
10193
#ifdef _SC_XOPEN_REALTIME_THREADS
10194
    {"SC_XOPEN_REALTIME_THREADS",       _SC_XOPEN_REALTIME_THREADS},
10195
#endif
10196
#ifdef _SC_XOPEN_SHM
10197
    {"SC_XOPEN_SHM",    _SC_XOPEN_SHM},
10198
#endif
10199
#ifdef _SC_XOPEN_UNIX
10200
    {"SC_XOPEN_UNIX",   _SC_XOPEN_UNIX},
10201
#endif
10202
#ifdef _SC_XOPEN_VERSION
10203
    {"SC_XOPEN_VERSION",        _SC_XOPEN_VERSION},
10204
#endif
10205
#ifdef _SC_XOPEN_XCU_VERSION
10206
    {"SC_XOPEN_XCU_VERSION",    _SC_XOPEN_XCU_VERSION},
10207
#endif
10208
#ifdef _SC_XOPEN_XPG2
10209
    {"SC_XOPEN_XPG2",   _SC_XOPEN_XPG2},
10210
#endif
10211
#ifdef _SC_XOPEN_XPG3
10212
    {"SC_XOPEN_XPG3",   _SC_XOPEN_XPG3},
10213
#endif
10214
#ifdef _SC_XOPEN_XPG4
10215
    {"SC_XOPEN_XPG4",   _SC_XOPEN_XPG4},
10216
#endif
10217
};
10218

10219
static int
10220
conv_sysconf_confname(PyObject *arg, int *valuep)
10221
{
10222
    return conv_confname(arg, valuep, posix_constants_sysconf,
inline
           
conv_confname too costly to inline (cost=335, threshold=250) 
conv_sysconf_confname
inline
           
conv_confname will not be inlined into conv_sysconf_confname 
conv_sysconf_confname
10223
                         sizeof(posix_constants_sysconf)
10224
                           / sizeof(struct constdef));
10225
}
10226

10227

10228
/*[clinic input]
10229
os.sysconf -> long
10230
    name: sysconf_confname
10231
    /
10232

10233
Return an integer-valued system configuration variable.
10234
[clinic start generated code]*/
10235

10236
static long
10237
os_sysconf_impl(PyObject *module, int name)
10238
/*[clinic end generated code: output=3662f945fc0cc756 input=279e3430a33f29e4]*/
10239
{
10240
    long value;
10241

10242
    errno = 0;
inline
    
__errno_location will not be inlined into os_sysconf_impl because its definition is unavailable 
os_sysconf_impl
10243
    value = sysconf(name);
inline
            
sysconf will not be inlined into os_sysconf_impl because its definition is unavailable 
os_sysconf_impl
10244
    if (value == -1 && errno != 0)
gvn
                       
load of type i32 not eliminated in favor of store because it is clobbered by call 
os_sysconf_impl
gvn
                       
load of type i32 not eliminated in favor of store because it is clobbered by call 
os_sysconf
10245
        posix_error();
inline
        
posix_error can be inlined into os_sysconf_impl with cost=10 (threshold=375) 
os_sysconf_impl
inline
        
posix_error inlined into os_sysconf_impl 
os_sysconf_impl
10246
    return value;
10247
}
10248
#endif /* HAVE_SYSCONF */
10249

10250

10251
/* This code is used to ensure that the tables of configuration value names
10252
 * are in sorted order as required by conv_confname(), and also to build
10253
 * the exported dictionaries that are used to publish information about the
10254
 * names available on the host platform.
10255
 *
10256
 * Sorting the table at runtime ensures that the table is properly ordered
10257
 * when used, even for platforms we're not able to test on.  It also makes
10258
 * it easier to add additional entries to the tables.
10259
 */
10260

10261
static int
10262
cmp_constdefs(const void *v1,  const void *v2)
10263
{
10264
    const struct constdef *c1 =
10265
    (const struct constdef *) v1;
10266
    const struct constdef *c2 =
10267
    (const struct constdef *) v2;
10268

10269
    return strcmp(c1->name, c2->name);
inline
           
strcmp will not be inlined into cmp_constdefs because its definition is unavailable 
cmp_constdefs
10270
}
10271

10272
static int
10273
setup_confname_table(struct constdef *table, size_t tablesize,
10274
                     const char *tablename, PyObject *module)
10275
{
10276
    PyObject *d = NULL;
10277
    size_t i;
10278

10279
    qsort(table, tablesize, sizeof(struct constdef), cmp_constdefs);
inline
    
qsort will not be inlined into setup_confname_table because its definition is unavailable 
setup_confname_table
10280
    d = PyDict_New();
inline
        
PyDict_New will not be inlined into setup_confname_table because its definition is unavailable 
setup_confname_table
10281
    if (d == NULL)
10282
        return -1;
10283

10284
    for (i=0; i < tablesize; ++i) {
loop-vectorize
    
loop not vectorized: loop control flow is not understood by vectorizer 
setup_confname_table
loop-vectorize
    
loop not vectorized 
setup_confname_table
10285
        PyObject *o = PyLong_FromLong(table[i].value);
inline
                      
PyLong_FromLong will not be inlined into setup_confname_table because its definition is unavailable 
setup_confname_table
10286
        if (o == NULL || PyDict_SetItemString(d, table[i].name, o) == -1) {
inline
                         
PyDict_SetItemString will not be inlined into setup_confname_table because its definition is unavailable 
setup_confname_table
gvn
                                                          
load of type i8* not eliminated because it is clobbered by call 
setup_confname_table
10287
            Py_XDECREF(o);
gvn
            
load of type i64 not eliminated because it is clobbered by call 
setup_confname_table
10288
            Py_DECREF(d);
gvn
            
load of type i64 not eliminated because it is clobbered by call 
setup_confname_table
10289
            return -1;
10290
        }
10291
        Py_DECREF(o);
gvn
        
load of type i64 not eliminated because it is clobbered by call 
setup_confname_table
10292
    }
10293
    return PyModule_AddObject(module, tablename, d);
inline
           
PyModule_AddObject will not be inlined into setup_confname_table because its definition is unavailable 
setup_confname_table
10294
}
10295

10296
/* Return -1 on failure, 0 on success. */
10297
static int
10298
setup_confname_tables(PyObject *module)
10299
{
10300
#if defined(HAVE_FPATHCONF) || defined(HAVE_PATHCONF)
10301
    if (setup_confname_table(posix_constants_pathconf,
inline
        
setup_confname_table too costly to inline (cost=360, threshold=250) 
setup_confname_tables
inline
        
setup_confname_table will not be inlined into setup_confname_tables 
setup_confname_tables
inline
        
setup_confname_table too costly to inline (cost=360, threshold=250) 
PyInit_posix
inline
        
setup_confname_table will not be inlined into PyInit_posix 
PyInit_posix
10302
                             sizeof(posix_constants_pathconf)
10303
                               / sizeof(struct constdef),
10304
                             "pathconf_names", module))
10305
        return -1;
10306
#endif
10307
#ifdef HAVE_CONFSTR
10308
    if (setup_confname_table(posix_constants_confstr,
inline
        
setup_confname_table too costly to inline (cost=360, threshold=250) 
setup_confname_tables
inline
        
setup_confname_table will not be inlined into setup_confname_tables 
setup_confname_tables
inline
        
setup_confname_table too costly to inline (cost=360, threshold=250) 
PyInit_posix
inline
        
setup_confname_table will not be inlined into PyInit_posix 
PyInit_posix
10309
                             sizeof(posix_constants_confstr)
10310
                               / sizeof(struct constdef),
10311
                             "confstr_names", module))
10312
        return -1;
10313
#endif
10314
#ifdef HAVE_SYSCONF
10315
    if (setup_confname_table(posix_constants_sysconf,
inline
        
setup_confname_table too costly to inline (cost=360, threshold=250) 
setup_confname_tables
inline
        
setup_confname_table will not be inlined into setup_confname_tables 
setup_confname_tables
inline
        
setup_confname_table too costly to inline (cost=360, threshold=250) 
PyInit_posix
inline
        
setup_confname_table will not be inlined into PyInit_posix 
PyInit_posix
10316
                             sizeof(posix_constants_sysconf)
10317
                               / sizeof(struct constdef),
10318
                             "sysconf_names", module))
10319
        return -1;
10320
#endif
10321
    return 0;
10322
}
10323

10324

10325
/*[clinic input]
10326
os.abort
10327

10328
Abort the interpreter immediately.
10329

10330
This function 'dumps core' or otherwise fails in the hardest way possible
10331
on the hosting operating system.  This function never returns.
10332
[clinic start generated code]*/
10333

10334
static PyObject *
10335
os_abort_impl(PyObject *module)
10336
/*[clinic end generated code: output=dcf52586dad2467c input=cf2c7d98bc504047]*/
10337
{
10338
    abort();
inline
    
abort will not be inlined into os_abort_impl because its definition is unavailable 
os_abort_impl
10339
    /*NOTREACHED*/
10340
    Py_FatalError("abort() called from Python code didn't abort!");
10341
    return NULL;
10342
}
10343

10344
#ifdef MS_WINDOWS
10345
/* Grab ShellExecute dynamically from shell32 */
10346
static int has_ShellExecute = -1;
10347
static HINSTANCE (CALLBACK *Py_ShellExecuteW)(HWND, LPCWSTR, LPCWSTR, LPCWSTR,
10348
                                              LPCWSTR, INT);
10349
static int
10350
check_ShellExecute()
10351
{
10352
    HINSTANCE hShell32;
10353

10354
    /* only recheck */
10355
    if (-1 == has_ShellExecute) {
10356
        Py_BEGIN_ALLOW_THREADS
10357
        hShell32 = LoadLibraryW(L"SHELL32");
10358
        Py_END_ALLOW_THREADS
10359
        if (hShell32) {
10360
            *(FARPROC*)&Py_ShellExecuteW = GetProcAddress(hShell32,
10361
                                            "ShellExecuteW");
10362
            has_ShellExecute = Py_ShellExecuteW != NULL;
10363
        } else {
10364
            has_ShellExecute = 0;
10365
        }
10366
    }
10367
    return has_ShellExecute;
10368
}
10369

10370

10371
/*[clinic input]
10372
os.startfile
10373
    filepath: path_t
10374
    operation: Py_UNICODE = NULL
10375

10376
startfile(filepath [, operation])
10377

10378
Start a file with its associated application.
10379

10380
When "operation" is not specified or "open", this acts like
10381
double-clicking the file in Explorer, or giving the file name as an
10382
argument to the DOS "start" command: the file is opened with whatever
10383
application (if any) its extension is associated.
10384
When another "operation" is given, it specifies what should be done with
10385
the file.  A typical operation is "print".
10386

10387
startfile returns as soon as the associated application is launched.
10388
There is no option to wait for the application to close, and no way
10389
to retrieve the application's exit status.
10390

10391
The filepath is relative to the current directory.  If you want to use
10392
an absolute path, make sure the first character is not a slash ("/");
10393
the underlying Win32 ShellExecute function doesn't work if it is.
10394
[clinic start generated code]*/
10395

10396
static PyObject *
10397
os_startfile_impl(PyObject *module, path_t *filepath, Py_UNICODE *operation)
10398
/*[clinic end generated code: output=912ceba79acfa1c9 input=63950bf2986380d0]*/
10399
{
10400
    HINSTANCE rc;
10401

10402
    if(!check_ShellExecute()) {
10403
        /* If the OS doesn't have ShellExecute, return a
10404
           NotImplementedError. */
10405
        return PyErr_Format(PyExc_NotImplementedError,
10406
            "startfile not available on this platform");
10407
    }
10408

10409
    Py_BEGIN_ALLOW_THREADS
10410
    rc = Py_ShellExecuteW((HWND)0, operation, filepath->wide,
10411
                          NULL, NULL, SW_SHOWNORMAL);
10412
    Py_END_ALLOW_THREADS
10413

10414
    if (rc <= (HINSTANCE)32) {
10415
        win32_error_object("startfile", filepath->object);
10416
        return NULL;
10417
    }
10418
    Py_RETURN_NONE;
10419
}
10420
#endif /* MS_WINDOWS */
10421

10422

10423
#ifdef HAVE_GETLOADAVG
10424
/*[clinic input]
10425
os.getloadavg
10426

10427
Return average recent system load information.
10428

10429
Return the number of processes in the system run queue averaged over
10430
the last 1, 5, and 15 minutes as a tuple of three floats.
10431
Raises OSError if the load average was unobtainable.
10432
[clinic start generated code]*/
10433

10434
static PyObject *
10435
os_getloadavg_impl(PyObject *module)
10436
/*[clinic end generated code: output=9ad3a11bfb4f4bd2 input=3d6d826b76d8a34e]*/
10437
{
10438
    double loadavg[3];
10439
    if (getloadavg(loadavg, 3)!=3) {
inline
        
getloadavg will not be inlined into os_getloadavg_impl because its definition is unavailable 
os_getloadavg_impl
10440
        PyErr_SetString(PyExc_OSError, "Load averages are unobtainable");
inline
        
PyErr_SetString will not be inlined into os_getloadavg_impl because its definition is unavailable 
os_getloadavg_impl
gvn
                        
load of type %struct._object* not eliminated because it is clobbered by call 
os_getloadavg_impl
gvn
                        
load of type %struct._object* not eliminated because it is clobbered by call 
os_getloadavg
10441
        return NULL;
10442
    } else
10443
        return Py_BuildValue("ddd", loadavg[0], loadavg[1], loadavg[2]);
inline
               
_Py_BuildValue_SizeT will not be inlined into os_getloadavg_impl because its definition is unavailable 
os_getloadavg_impl
gvn
                                    
load of type double not eliminated because it is clobbered by call 
os_getloadavg_impl
gvn
                                                
load of type double not eliminated because it is clobbered by call 
os_getloadavg_impl
gvn
                                                            
load of type double not eliminated because it is clobbered by call 
os_getloadavg_impl
gvn
                                    
load of type double not eliminated because it is clobbered by call 
os_getloadavg
gvn
                                                
load of type double not eliminated because it is clobbered by call 
os_getloadavg
gvn
                                                            
load of type double not eliminated because it is clobbered by call 
os_getloadavg
10444
}
10445
#endif /* HAVE_GETLOADAVG */
10446

10447

10448
/*[clinic input]
10449
os.device_encoding
10450
    fd: int
10451

10452
Return a string describing the encoding of a terminal's file descriptor.
10453

10454
The file descriptor must be attached to a terminal.
10455
If the device is not a terminal, return None.
10456
[clinic start generated code]*/
10457

10458
static PyObject *
10459
os_device_encoding_impl(PyObject *module, int fd)
10460
/*[clinic end generated code: output=e0d294bbab7e8c2b input=9e1d4a42b66df312]*/
10461
{
10462
    return _Py_device_encoding(fd);
inline
           
_Py_device_encoding will not be inlined into os_device_encoding_impl because its definition is unavailable 
os_device_encoding_impl
10463
}
10464

10465

10466
#ifdef HAVE_SETRESUID
10467
/*[clinic input]
10468
os.setresuid
10469

10470
    ruid: uid_t
10471
    euid: uid_t
10472
    suid: uid_t
10473
    /
10474

10475
Set the current process's real, effective, and saved user ids.
10476
[clinic start generated code]*/
10477

10478
static PyObject *
10479
os_setresuid_impl(PyObject *module, uid_t ruid, uid_t euid, uid_t suid)
10480
/*[clinic end generated code: output=834a641e15373e97 input=9e33cb79a82792f3]*/
10481
{
10482
    if (setresuid(ruid, euid, suid) < 0)
inline
        
setresuid will not be inlined into os_setresuid_impl because its definition is unavailable 
os_setresuid_impl
10483
        return posix_error();
inline
               
posix_error can be inlined into os_setresuid_impl with cost=10 (threshold=375) 
os_setresuid_impl
inline
               
posix_error inlined into os_setresuid_impl 
os_setresuid_impl
10484
    Py_RETURN_NONE;
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_setresuid_impl
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_setresuid
10485
}
10486
#endif /* HAVE_SETRESUID */
10487

10488

10489
#ifdef HAVE_SETRESGID
10490
/*[clinic input]
10491
os.setresgid
10492

10493
    rgid: gid_t
10494
    egid: gid_t
10495
    sgid: gid_t
10496
    /
10497

10498
Set the current process's real, effective, and saved group ids.
10499
[clinic start generated code]*/
10500

10501
static PyObject *
10502
os_setresgid_impl(PyObject *module, gid_t rgid, gid_t egid, gid_t sgid)
10503
/*[clinic end generated code: output=6aa402f3d2e514a9 input=33e9e0785ef426b1]*/
10504
{
10505
    if (setresgid(rgid, egid, sgid) < 0)
inline
        
setresgid will not be inlined into os_setresgid_impl because its definition is unavailable 
os_setresgid_impl
10506
        return posix_error();
inline
               
posix_error can be inlined into os_setresgid_impl with cost=10 (threshold=375) 
os_setresgid_impl
inline
               
posix_error inlined into os_setresgid_impl 
os_setresgid_impl
10507
    Py_RETURN_NONE;
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_setresgid_impl
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_setresgid
10508
}
10509
#endif /* HAVE_SETRESGID */
10510

10511

10512
#ifdef HAVE_GETRESUID
10513
/*[clinic input]
10514
os.getresuid
10515

10516
Return a tuple of the current process's real, effective, and saved user ids.
10517
[clinic start generated code]*/
10518

10519
static PyObject *
10520
os_getresuid_impl(PyObject *module)
10521
/*[clinic end generated code: output=8e0becff5dece5bf input=41ccfa8e1f6517ad]*/
10522
{
10523
    uid_t ruid, euid, suid;
10524
    if (getresuid(&ruid, &euid, &suid) < 0)
inline
        
getresuid will not be inlined into os_getresuid_impl because its definition is unavailable 
os_getresuid_impl
10525
        return posix_error();
inline
               
posix_error can be inlined into os_getresuid_impl with cost=10 (threshold=375) 
os_getresuid_impl
inline
               
posix_error inlined into os_getresuid_impl 
os_getresuid_impl
10526
    return Py_BuildValue("(NNN)", _PyLong_FromUid(ruid),
inline
           
_Py_BuildValue_SizeT will not be inlined into os_getresuid_impl because its definition is unavailable 
os_getresuid_impl
inline
                                  
_PyLong_FromUid can be inlined into os_getresuid_impl with cost=45 (threshold=250) 
os_getresuid_impl
inline
                                  
_PyLong_FromUid inlined into os_getresuid_impl 
os_getresuid_impl
gvn
                                                  
load of type i32 not eliminated because it is clobbered by call 
os_getresuid_impl
gvn
                                                  
load of type i32 not eliminated because it is clobbered by call 
os_getresuid
10527
                                  _PyLong_FromUid(euid),
inline
                                  
_PyLong_FromUid can be inlined into os_getresuid_impl with cost=45 (threshold=250) 
os_getresuid_impl
inline
                                  
_PyLong_FromUid inlined into os_getresuid_impl 
os_getresuid_impl
gvn
                                                  
load of type i32 not eliminated because it is clobbered by call 
os_getresuid_impl
gvn
                                                  
load of type i32 not eliminated because it is clobbered by call 
os_getresuid
10528
                                  _PyLong_FromUid(suid));
inline
                                  
_PyLong_FromUid can be inlined into os_getresuid_impl with cost=45 (threshold=250) 
os_getresuid_impl
inline
                                  
_PyLong_FromUid inlined into os_getresuid_impl 
os_getresuid_impl
gvn
                                                  
load of type i32 not eliminated because it is clobbered by call 
os_getresuid_impl
gvn
                                                  
load of type i32 not eliminated because it is clobbered by call 
os_getresuid
10529
}
10530
#endif /* HAVE_GETRESUID */
10531

10532

10533
#ifdef HAVE_GETRESGID
10534
/*[clinic input]
10535
os.getresgid
10536

10537
Return a tuple of the current process's real, effective, and saved group ids.
10538
[clinic start generated code]*/
10539

10540
static PyObject *
10541
os_getresgid_impl(PyObject *module)
10542
/*[clinic end generated code: output=2719c4bfcf27fb9f input=517e68db9ca32df6]*/
10543
{
10544
    gid_t rgid, egid, sgid;
10545
    if (getresgid(&rgid, &egid, &sgid) < 0)
inline
        
getresgid will not be inlined into os_getresgid_impl because its definition is unavailable 
os_getresgid_impl
10546
        return posix_error();
inline
               
posix_error can be inlined into os_getresgid_impl with cost=-14990 (threshold=375) 
os_getresgid_impl
inline
               
posix_error inlined into os_getresgid_impl 
os_getresgid_impl
10547
    return Py_BuildValue("(NNN)", _PyLong_FromGid(rgid),
inline
           
_Py_BuildValue_SizeT will not be inlined into os_getresgid_impl because its definition is unavailable 
os_getresgid_impl
inline
                                  
_PyLong_FromGid can be inlined into os_getresgid_impl with cost=45 (threshold=250) 
os_getresgid_impl
inline
                                  
_PyLong_FromGid inlined into os_getresgid_impl 
os_getresgid_impl
gvn
                                                  
load of type i32 not eliminated because it is clobbered by call 
os_getresgid_impl
gvn
                                                  
load of type i32 not eliminated because it is clobbered by call 
os_getresgid
10548
                                  _PyLong_FromGid(egid),
inline
                                  
_PyLong_FromGid can be inlined into os_getresgid_impl with cost=45 (threshold=250) 
os_getresgid_impl
inline
                                  
_PyLong_FromGid inlined into os_getresgid_impl 
os_getresgid_impl
gvn
                                                  
load of type i32 not eliminated because it is clobbered by call 
os_getresgid_impl
gvn
                                                  
load of type i32 not eliminated because it is clobbered by call 
os_getresgid
10549
                                  _PyLong_FromGid(sgid));
inline
                                  
_PyLong_FromGid can be inlined into os_getresgid_impl with cost=45 (threshold=250) 
os_getresgid_impl
inline
                                  
_PyLong_FromGid inlined into os_getresgid_impl 
os_getresgid_impl
gvn
                                                  
load of type i32 not eliminated because it is clobbered by call 
os_getresgid_impl
gvn
                                                  
load of type i32 not eliminated because it is clobbered by call 
os_getresgid
10550
}
10551
#endif /* HAVE_GETRESGID */
10552

10553

10554
#ifdef USE_XATTRS
10555
/*[clinic input]
10556
os.getxattr
10557

10558
    path: path_t(allow_fd=True)
10559
    attribute: path_t
10560
    *
10561
    follow_symlinks: bool = True
10562

10563
Return the value of extended attribute attribute on path.
10564

10565
path may be either a string or an open file descriptor.
10566
If follow_symlinks is False, and the last element of the path is a symbolic
10567
  link, getxattr will examine the symbolic link itself instead of the file
10568
  the link points to.
10569

10570
[clinic start generated code]*/
10571

10572
static PyObject *
10573
os_getxattr_impl(PyObject *module, path_t *path, path_t *attribute,
10574
                 int follow_symlinks)
10575
/*[clinic end generated code: output=5f2f44200a43cff2 input=8c8ea3bab78d89c2]*/
10576
{
10577
    Py_ssize_t i;
10578
    PyObject *buffer = NULL;
10579

10580
    if (fd_and_follow_symlinks_invalid("getxattr", path->fd, follow_symlinks))
inline
        
fd_and_follow_symlinks_invalid can be inlined into os_getxattr_impl with cost=25 (threshold=250) 
os_getxattr_impl
inline
        
fd_and_follow_symlinks_invalid inlined into os_getxattr_impl 
os_getxattr_impl
gvn
                                                         
load of type i32 not eliminated in favor of store because it is clobbered by call 
os_getxattr
10581
        return NULL;
10582

10583
    for (i = 0; ; i++) {
loop-unroll
    
completely unrolled loop with 2 iterations 
os_getxattr_impl
10584
        void *ptr;
10585
        ssize_t result;
10586
        static const Py_ssize_t buffer_sizes[] = {128, XATTR_SIZE_MAX, 0};
10587
        Py_ssize_t buffer_size = buffer_sizes[i];
10588
        if (!buffer_size) {
10589
            path_error(path);
inline
            
path_error can be inlined into os_getxattr_impl with cost=10 (threshold=375) 
os_getxattr_impl
inline
            
path_error inlined into os_getxattr_impl 
os_getxattr_impl
10590
            return NULL;
10591
        }
10592
        buffer = PyBytes_FromStringAndSize(NULL, buffer_size);
inline
                 
PyBytes_FromStringAndSize will not be inlined into os_getxattr_impl because its definition is unavailable 
os_getxattr_impl
10593
        if (!buffer)
10594
            return NULL;
10595
        ptr = PyBytes_AS_STRING(buffer);
10596

10597
        Py_BEGIN_ALLOW_THREADS;
inline
        
PyEval_SaveThread will not be inlined into os_getxattr_impl because its definition is unavailable 
os_getxattr_impl
10598
        if (path->fd >= 0)
licm
                  
failed to move load with loop-invariant address because the loop may invalidate its value 
os_getxattr_impl
gvn
                  
load of type i32 not eliminated in favor of load because it is clobbered by call 
os_getxattr_impl
gvn
                  
load of type i32 not eliminated because it is clobbered by call 
os_getxattr
10599
            result = fgetxattr(path->fd, attribute->narrow, ptr, buffer_size);
inline
                     
fgetxattr will not be inlined into os_getxattr_impl because its definition is unavailable 
os_getxattr_impl
licm
                                                    
hosting getelementptr 
os_getxattr_impl
licm
                                                    
failed to move load with loop-invariant address because the loop may invalidate its value 
os_getxattr_impl
gvn
                                                    
load of type i8* not eliminated because it is clobbered by call 
os_getxattr_impl
gvn
                                                    
load of type i8* not eliminated because it is clobbered by call 
os_getxattr
10600
        else if (follow_symlinks)
licm
                 
hosting icmp 
os_getxattr_impl
10601
            result = getxattr(path->narrow, attribute->narrow, ptr, buffer_size);
inline
                     
getxattr will not be inlined into os_getxattr_impl because its definition is unavailable 
os_getxattr_impl
10602
        else
10603
            result = lgetxattr(path->narrow, attribute->narrow, ptr, buffer_size);
inline
                     
lgetxattr will not be inlined into os_getxattr_impl because its definition is unavailable 
os_getxattr_impl
10604
        Py_END_ALLOW_THREADS;
inline
        
PyEval_RestoreThread will not be inlined into os_getxattr_impl because its definition is unavailable 
os_getxattr_impl
10605

10606
        if (result < 0) {
10607
            Py_DECREF(buffer);
licm
            
failed to move load with loop-invariant address because the loop may invalidate its value 
os_getxattr_impl
licm
            
Moving accesses to memory location out of the loop 
os_getxattr_impl
gvn
            
load of type i64 not eliminated because it is clobbered by call 
os_getxattr_impl
gvn
            
load of type i64 not eliminated because it is clobbered by call 
os_getxattr
10608
            if (errno == ERANGE)
inline
                
__errno_location will not be inlined into os_getxattr_impl because its definition is unavailable 
os_getxattr_impl
gvn
                
load of type i32 not eliminated in favor of load because it is clobbered by call 
os_getxattr_impl
gvn
                
load of type i32 not eliminated in favor of load because it is clobbered by call 
os_getxattr
10609
                continue;
10610
            path_error(path);
inline
            
path_error can be inlined into os_getxattr_impl with cost=10 (threshold=375) 
os_getxattr_impl
inline
            
path_error inlined into os_getxattr_impl 
os_getxattr_impl
10611
            return NULL;
10612
        }
10613

10614
        if (result != buffer_size) {
10615
            /* Can only shrink. */
10616
            _PyBytes_Resize(&buffer, result);
inline
            
_PyBytes_Resize will not be inlined into os_getxattr_impl because its definition is unavailable 
os_getxattr_impl
10617
        }
10618
        break;
10619
    }
10620

10621
    return buffer;
gvn
           
load of type %struct._object* not eliminated because it is clobbered by call 
os_getxattr_impl
gvn
           
load eliminated by PRE 
os_getxattr_impl
10622
}
10623

10624

10625
/*[clinic input]
10626
os.setxattr
10627

10628
    path: path_t(allow_fd=True)
10629
    attribute: path_t
10630
    value: Py_buffer
10631
    flags: int = 0
10632
    *
10633
    follow_symlinks: bool = True
10634

10635
Set extended attribute attribute on path to value.
10636

10637
path may be either a string or an open file descriptor.
10638
If follow_symlinks is False, and the last element of the path is a symbolic
10639
  link, setxattr will modify the symbolic link itself instead of the file
10640
  the link points to.
10641

10642
[clinic start generated code]*/
10643

10644
static PyObject *
10645
os_setxattr_impl(PyObject *module, path_t *path, path_t *attribute,
10646
                 Py_buffer *value, int flags, int follow_symlinks)
10647
/*[clinic end generated code: output=98b83f63fdde26bb input=f0d26833992015c2]*/
10648
{
10649
    ssize_t result;
10650

10651
    if (fd_and_follow_symlinks_invalid("setxattr", path->fd, follow_symlinks))
inline
        
fd_and_follow_symlinks_invalid can be inlined into os_setxattr_impl with cost=25 (threshold=250) 
os_setxattr_impl
inline
        
fd_and_follow_symlinks_invalid inlined into os_setxattr_impl 
os_setxattr_impl
gvn
                                                         
load of type i32 not eliminated in favor of store because it is clobbered by call 
os_setxattr
10652
        return NULL;
10653

10654
    Py_BEGIN_ALLOW_THREADS;
inline
    
PyEval_SaveThread will not be inlined into os_setxattr_impl because its definition is unavailable 
os_setxattr_impl
10655
    if (path->fd > -1)
gvn
              
load of type i32 not eliminated in favor of load because it is clobbered by call 
os_setxattr_impl
gvn
              
load of type i32 not eliminated because it is clobbered by call 
os_setxattr
10656
        result = fsetxattr(path->fd, attribute->narrow,
inline
                 
fsetxattr will not be inlined into os_setxattr_impl because its definition is unavailable 
os_setxattr_impl
gvn
                                                
load of type i8* not eliminated because it is clobbered by call 
os_setxattr_impl
gvn
                                                
load of type i8* not eliminated because it is clobbered by call 
os_setxattr
10657
                           value->buf, value->len, flags);
gvn
                                              
load of type i64 not eliminated because it is clobbered by call 
os_setxattr_impl
gvn
                                  
load of type i8* not eliminated because it is clobbered by call 
os_setxattr_impl
gvn
                                              
load of type i64 not eliminated because it is clobbered by call 
os_setxattr
gvn
                                  
load of type i8* not eliminated because it is clobbered by call 
os_setxattr
10658
    else if (follow_symlinks)
10659
        result = setxattr(path->narrow, attribute->narrow,
inline
                 
setxattr will not be inlined into os_setxattr_impl because its definition is unavailable 
os_setxattr_impl
10660
                           value->buf, value->len, flags);
10661
    else
10662
        result = lsetxattr(path->narrow, attribute->narrow,
inline
                 
lsetxattr will not be inlined into os_setxattr_impl because its definition is unavailable 
os_setxattr_impl
10663
                           value->buf, value->len, flags);
10664
    Py_END_ALLOW_THREADS;
inline
    
PyEval_RestoreThread will not be inlined into os_setxattr_impl because its definition is unavailable 
os_setxattr_impl
10665

10666
    if (result) {
10667
        path_error(path);
inline
        
path_error can be inlined into os_setxattr_impl with cost=10 (threshold=375) 
os_setxattr_impl
inline
        
path_error inlined into os_setxattr_impl 
os_setxattr_impl
10668
        return NULL;
10669
    }
10670

10671
    Py_RETURN_NONE;
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_setxattr_impl
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_setxattr
10672
}
10673

10674

10675
/*[clinic input]
10676
os.removexattr
10677

10678
    path: path_t(allow_fd=True)
10679
    attribute: path_t
10680
    *
10681
    follow_symlinks: bool = True
10682

10683
Remove extended attribute attribute on path.
10684

10685
path may be either a string or an open file descriptor.
10686
If follow_symlinks is False, and the last element of the path is a symbolic
10687
  link, removexattr will modify the symbolic link itself instead of the file
10688
  the link points to.
10689

10690
[clinic start generated code]*/
10691

10692
static PyObject *
10693
os_removexattr_impl(PyObject *module, path_t *path, path_t *attribute,
10694
                    int follow_symlinks)
10695
/*[clinic end generated code: output=521a51817980cda6 input=cdb54834161e3329]*/
10696
{
10697
    ssize_t result;
10698

10699
    if (fd_and_follow_symlinks_invalid("removexattr", path->fd, follow_symlinks))
inline
        
fd_and_follow_symlinks_invalid can be inlined into os_removexattr_impl with cost=25 (threshold=250) 
os_removexattr_impl
inline
        
fd_and_follow_symlinks_invalid inlined into os_removexattr_impl 
os_removexattr_impl
gvn
                                                            
load of type i32 not eliminated in favor of store because it is clobbered by call 
os_removexattr
10700
        return NULL;
10701

10702
    Py_BEGIN_ALLOW_THREADS;
inline
    
PyEval_SaveThread will not be inlined into os_removexattr_impl because its definition is unavailable 
os_removexattr_impl
10703
    if (path->fd > -1)
gvn
              
load of type i32 not eliminated in favor of load because it is clobbered by call 
os_removexattr_impl
gvn
              
load of type i32 not eliminated because it is clobbered by call 
os_removexattr
10704
        result = fremovexattr(path->fd, attribute->narrow);
inline
                 
fremovexattr will not be inlined into os_removexattr_impl because its definition is unavailable 
os_removexattr_impl
gvn
                                                   
load of type i8* not eliminated because it is clobbered by call 
os_removexattr_impl
gvn
                                                   
load of type i8* not eliminated because it is clobbered by call 
os_removexattr
10705
    else if (follow_symlinks)
10706
        result = removexattr(path->narrow, attribute->narrow);
inline
                 
removexattr will not be inlined into os_removexattr_impl because its definition is unavailable 
os_removexattr_impl
10707
    else
10708
        result = lremovexattr(path->narrow, attribute->narrow);
inline
                 
lremovexattr will not be inlined into os_removexattr_impl because its definition is unavailable 
os_removexattr_impl
10709
    Py_END_ALLOW_THREADS;
inline
    
PyEval_RestoreThread will not be inlined into os_removexattr_impl because its definition is unavailable 
os_removexattr_impl
10710

10711
    if (result) {
10712
        return path_error(path);
inline
               
path_error can be inlined into os_removexattr_impl with cost=10 (threshold=375) 
os_removexattr_impl
inline
               
path_error inlined into os_removexattr_impl 
os_removexattr_impl
10713
    }
10714

10715
    Py_RETURN_NONE;
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_removexattr_impl
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_removexattr
10716
}
10717

10718

10719
/*[clinic input]
10720
os.listxattr
10721

10722
    path: path_t(allow_fd=True, nullable=True) = None
10723
    *
10724
    follow_symlinks: bool = True
10725

10726
Return a list of extended attributes on path.
10727

10728
path may be either None, a string, or an open file descriptor.
10729
if path is None, listxattr will examine the current directory.
10730
If follow_symlinks is False, and the last element of the path is a symbolic
10731
  link, listxattr will examine the symbolic link itself instead of the file
10732
  the link points to.
10733
[clinic start generated code]*/
10734

10735
static PyObject *
10736
os_listxattr_impl(PyObject *module, path_t *path, int follow_symlinks)
10737
/*[clinic end generated code: output=bebdb4e2ad0ce435 input=08cca53ac0b07c13]*/
10738
{
10739
    Py_ssize_t i;
10740
    PyObject *result = NULL;
10741
    const char *name;
10742
    char *buffer = NULL;
10743

10744
    if (fd_and_follow_symlinks_invalid("listxattr", path->fd, follow_symlinks))
inline
        
fd_and_follow_symlinks_invalid can be inlined into os_listxattr_impl with cost=-14975 (threshold=250) 
os_listxattr_impl
inline
        
fd_and_follow_symlinks_invalid inlined into os_listxattr_impl 
os_listxattr_impl
gvn
                                                          
load of type i32 not eliminated in favor of store because it is clobbered by call 
os_listxattr
10745
        goto exit;
10746

10747
    name = path->narrow ? path->narrow : ".";
gvn
                 
load of type i8* not eliminated because it is clobbered by call 
os_listxattr
10748

10749
    for (i = 0; ; i++) {
loop-unroll
    
completely unrolled loop with 2 iterations 
os_listxattr_impl
10750
        const char *start, *trace, *end;
10751
        ssize_t length;
10752
        static const Py_ssize_t buffer_sizes[] = { 256, XATTR_LIST_MAX, 0 };
10753
        Py_ssize_t buffer_size = buffer_sizes[i];
10754
        if (!buffer_size) {
10755
            /* ERANGE */
10756
            path_error(path);
inline
            
path_error can be inlined into os_listxattr_impl with cost=10 (threshold=375) 
os_listxattr_impl
inline
            
path_error inlined into os_listxattr_impl 
os_listxattr_impl
10757
            break;
10758
        }
10759
        buffer = PyMem_MALLOC(buffer_size);
inline
                 
PyMem_Malloc will not be inlined into os_listxattr_impl because its definition is unavailable 
os_listxattr_impl
10760
        if (!buffer) {
10761
            PyErr_NoMemory();
inline
            
PyErr_NoMemory will not be inlined into os_listxattr_impl because its definition is unavailable 
os_listxattr_impl
10762
            break;
10763
        }
10764

10765
        Py_BEGIN_ALLOW_THREADS;
inline
        
PyEval_SaveThread will not be inlined into os_listxattr_impl because its definition is unavailable 
os_listxattr_impl
10766
        if (path->fd > -1)
licm
                  
failed to move load with loop-invariant address because the loop may invalidate its value 
os_listxattr_impl
gvn
                  
load of type i32 not eliminated in favor of load because it is clobbered by call 
os_listxattr_impl
gvn
                  
load of type i32 not eliminated because it is clobbered by call 
os_listxattr
10767
            length = flistxattr(path->fd, buffer, buffer_size);
inline
                     
flistxattr will not be inlined into os_listxattr_impl because its definition is unavailable 
os_listxattr_impl
10768
        else if (follow_symlinks)
licm
                 
hosting icmp 
os_listxattr_impl
10769
            length = listxattr(name, buffer, buffer_size);
inline
                     
listxattr will not be inlined into os_listxattr_impl because its definition is unavailable 
os_listxattr_impl
10770
        else
10771
            length = llistxattr(name, buffer, buffer_size);
inline
                     
llistxattr will not be inlined into os_listxattr_impl because its definition is unavailable 
os_listxattr_impl
10772
        Py_END_ALLOW_THREADS;
inline
        
PyEval_RestoreThread will not be inlined into os_listxattr_impl because its definition is unavailable 
os_listxattr_impl
10773

10774
        if (length < 0) {
10775
            if (errno == ERANGE) {
inline
                
__errno_location will not be inlined into os_listxattr_impl because its definition is unavailable 
os_listxattr_impl
gvn
                
load of type i32 not eliminated in favor of load because it is clobbered by call 
os_listxattr_impl
gvn
                
load of type i32 not eliminated in favor of load because it is clobbered by call 
os_listxattr
10776
                PyMem_FREE(buffer);
inline
                
PyMem_Free will not be inlined into os_listxattr_impl because its definition is unavailable 
os_listxattr_impl
10777
                buffer = NULL;
10778
                continue;
10779
            }
10780
            path_error(path);
inline
            
path_error can be inlined into os_listxattr_impl with cost=10 (threshold=375) 
os_listxattr_impl
inline
            
path_error inlined into os_listxattr_impl 
os_listxattr_impl
10781
            break;
10782
        }
10783

10784
        result = PyList_New(0);
inline
                 
PyList_New will not be inlined into os_listxattr_impl because its definition is unavailable 
os_listxattr_impl
10785
        if (!result) {
10786
            goto exit;
10787
        }
10788

10789
        end = buffer + length;
10790
        for (trace = start = buffer; trace != end; trace++) {
loop-vectorize
        
loop not vectorized: loop control flow is not understood by vectorizer 
os_listxattr
loop-vectorize
        
loop not vectorized 
os_listxattr
10791
            if (!*trace) {
gvn
                 
load of type i8 not eliminated because it is clobbered by call 
os_listxattr_impl
gvn
                 
load of type i8 not eliminated because it is clobbered by call 
os_listxattr
10792
                int error;
10793
                PyObject *attribute = PyUnicode_DecodeFSDefaultAndSize(start,
inline
                                      
PyUnicode_DecodeFSDefaultAndSize will not be inlined into os_listxattr_impl because its definition is unavailable 
os_listxattr_impl
10794
                                                                 trace - start);
10795
                if (!attribute) {
10796
                    Py_DECREF(result);
gvn
                    
load of type i64 not eliminated because it is clobbered by call 
os_listxattr_impl
gvn
                    
load of type i64 not eliminated because it is clobbered by call 
os_listxattr
10797
                    result = NULL;
10798
                    goto exit;
10799
                }
10800
                error = PyList_Append(result, attribute);
inline
                        
PyList_Append will not be inlined into os_listxattr_impl because its definition is unavailable 
os_listxattr_impl
10801
                Py_DECREF(attribute);
gvn
                
load of type i64 not eliminated because it is clobbered by call 
os_listxattr_impl
gvn
                
load of type i64 not eliminated because it is clobbered by call 
os_listxattr
10802
                if (error) {
10803
                    Py_DECREF(result);
gvn
                    
load of type i64 not eliminated because it is clobbered by call 
os_listxattr_impl
gvn
                    
load of type i64 not eliminated because it is clobbered by store 
os_listxattr
10804
                    result = NULL;
10805
                    goto exit;
10806
                }
10807
                start = trace + 1;
10808
            }
10809
        }
10810
    break;
10811
    }
10812
exit:
10813
    if (buffer)
10814
        PyMem_FREE(buffer);
inline
        
PyMem_Free will not be inlined into os_listxattr_impl because its definition is unavailable 
os_listxattr_impl
10815
    return result;
10816
}
10817
#endif /* USE_XATTRS */
10818

10819

10820
/*[clinic input]
10821
os.urandom
10822

10823
    size: Py_ssize_t
10824
    /
10825

10826
Return a bytes object containing random bytes suitable for cryptographic use.
10827
[clinic start generated code]*/
10828

10829
static PyObject *
10830
os_urandom_impl(PyObject *module, Py_ssize_t size)
10831
/*[clinic end generated code: output=42c5cca9d18068e9 input=4067cdb1b6776c29]*/
10832
{
10833
    PyObject *bytes;
10834
    int result;
10835

10836
    if (size < 0)
10837
        return PyErr_Format(PyExc_ValueError,
inline
               
PyErr_Format will not be inlined into os_urandom_impl because its definition is unavailable 
os_urandom_impl
gvn
                            
load of type %struct._object* not eliminated because it is clobbered by call 
os_urandom
10838
                            "negative argument not allowed");
10839
    bytes = PyBytes_FromStringAndSize(NULL, size);
inline
            
PyBytes_FromStringAndSize will not be inlined into os_urandom_impl because its definition is unavailable 
os_urandom_impl
10840
    if (bytes == NULL)
10841
        return NULL;
10842

10843
    result = _PyOS_URandom(PyBytes_AS_STRING(bytes), PyBytes_GET_SIZE(bytes));
inline
             
_PyOS_URandom will not be inlined into os_urandom_impl because its definition is unavailable 
os_urandom_impl
gvn
                                                     
load of type i64 not eliminated because it is clobbered by call 
os_urandom_impl
gvn
                                                     
load of type i64 not eliminated because it is clobbered by call 
os_urandom
10844
    if (result == -1) {
10845
        Py_DECREF(bytes);
gvn
        
load of type i64 not eliminated because it is clobbered by call 
os_urandom_impl
gvn
        
load of type i64 not eliminated because it is clobbered by call 
os_urandom
10846
        return NULL;
10847
    }
10848
    return bytes;
10849
}
10850

10851
/* Terminal size querying */
10852

10853
static PyTypeObject TerminalSizeType;
10854

10855
PyDoc_STRVAR(TerminalSize_docstring,
10856
    "A tuple of (columns, lines) for holding terminal window size");
10857

10858
static PyStructSequence_Field TerminalSize_fields[] = {
10859
    {"columns", "width of the terminal window in characters"},
10860
    {"lines", "height of the terminal window in characters"},
10861
    {NULL, NULL}
10862
};
10863

10864
static PyStructSequence_Desc TerminalSize_desc = {
10865
    "os.terminal_size",
10866
    TerminalSize_docstring,
10867
    TerminalSize_fields,
10868
    2,
10869
};
10870

10871
#if defined(TERMSIZE_USE_CONIO) || defined(TERMSIZE_USE_IOCTL)
10872
/* AC 3.5: fd should accept None */
10873
PyDoc_STRVAR(termsize__doc__,
10874
    "Return the size of the terminal window as (columns, lines).\n"        \
10875
    "\n"                                                                   \
10876
    "The optional argument fd (default standard output) specifies\n"       \
10877
    "which file descriptor should be queried.\n"                           \
10878
    "\n"                                                                   \
10879
    "If the file descriptor is not connected to a terminal, an OSError\n"  \
10880
    "is thrown.\n"                                                         \
10881
    "\n"                                                                   \
10882
    "This function will only be defined if an implementation is\n"         \
10883
    "available for this system.\n"                                         \
10884
    "\n"                                                                   \
10885
    "shutil.get_terminal_size is the high-level function which should \n"  \
10886
    "normally be used, os.get_terminal_size is the low-level implementation.");
10887

10888
static PyObject*
10889
get_terminal_size(PyObject *self, PyObject *args)
10890
{
10891
    int columns, lines;
10892
    PyObject *termsize;
10893

10894
    int fd = fileno(stdout);
inline
             
fileno will not be inlined into get_terminal_size because its definition is unavailable 
get_terminal_size
10895
    /* Under some conditions stdout may not be connected and
10896
     * fileno(stdout) may point to an invalid file descriptor. For example
10897
     * GUI apps don't have valid standard streams by default.
10898
     *
10899
     * If this happens, and the optional fd argument is not present,
10900
     * the ioctl below will fail returning EBADF. This is what we want.
10901
     */
10902

10903
    if (!PyArg_ParseTuple(args, "|i", &fd))
inline
         
_PyArg_ParseTuple_SizeT will not be inlined into get_terminal_size because its definition is unavailable 
get_terminal_size
10904
        return NULL;
10905

10906
#ifdef TERMSIZE_USE_IOCTL
10907
    {
10908
        struct winsize w;
10909
        if (ioctl(fd, TIOCGWINSZ, &w))
inline
            
ioctl will not be inlined into get_terminal_size because its definition is unavailable 
get_terminal_size
gvn
                  
load of type i32 not eliminated in favor of store because it is clobbered by call 
get_terminal_size
10910
            return PyErr_SetFromErrno(PyExc_OSError);
inline
                   
PyErr_SetFromErrno will not be inlined into get_terminal_size because its definition is unavailable 
get_terminal_size
gvn
                                      
load of type %struct._object* not eliminated because it is clobbered by call 
get_terminal_size
10911
        columns = w.ws_col;
gvn
                    
load of type i16 not eliminated because it is clobbered by call 
get_terminal_size
10912
        lines = w.ws_row;
gvn
                  
load of type i16 not eliminated because it is clobbered by call 
get_terminal_size
10913
    }
10914
#endif /* TERMSIZE_USE_IOCTL */
10915

10916
#ifdef TERMSIZE_USE_CONIO
10917
    {
10918
        DWORD nhandle;
10919
        HANDLE handle;
10920
        CONSOLE_SCREEN_BUFFER_INFO csbi;
10921
        switch (fd) {
10922
        case 0: nhandle = STD_INPUT_HANDLE;
10923
            break;
10924
        case 1: nhandle = STD_OUTPUT_HANDLE;
10925
            break;
10926
        case 2: nhandle = STD_ERROR_HANDLE;
10927
            break;
10928
        default:
10929
            return PyErr_Format(PyExc_ValueError, "bad file descriptor");
10930
        }
10931
        handle = GetStdHandle(nhandle);
10932
        if (handle == NULL)
10933
            return PyErr_Format(PyExc_OSError, "handle cannot be retrieved");
10934
        if (handle == INVALID_HANDLE_VALUE)
10935
            return PyErr_SetFromWindowsErr(0);
10936

10937
        if (!GetConsoleScreenBufferInfo(handle, &csbi))
10938
            return PyErr_SetFromWindowsErr(0);
10939

10940
        columns = csbi.srWindow.Right - csbi.srWindow.Left + 1;
10941
        lines = csbi.srWindow.Bottom - csbi.srWindow.Top + 1;
10942
    }
10943
#endif /* TERMSIZE_USE_CONIO */
10944

10945
    termsize = PyStructSequence_New(&TerminalSizeType);
inline
               
PyStructSequence_New will not be inlined into get_terminal_size because its definition is unavailable 
get_terminal_size
10946
    if (termsize == NULL)
10947
        return NULL;
10948
    PyStructSequence_SET_ITEM(termsize, 0, PyLong_FromLong(columns));
inline
    
PyLong_FromLong will not be inlined into get_terminal_size because its definition is unavailable 
get_terminal_size
10949
    PyStructSequence_SET_ITEM(termsize, 1, PyLong_FromLong(lines));
inline
    
PyLong_FromLong will not be inlined into get_terminal_size because its definition is unavailable 
get_terminal_size
10950
    if (PyErr_Occurred()) {
inline
        
PyErr_Occurred will not be inlined into get_terminal_size because its definition is unavailable 
get_terminal_size
10951
        Py_DECREF(termsize);
gvn
        
load of type i64 not eliminated because it is clobbered by call 
get_terminal_size
10952
        return NULL;
10953
    }
10954
    return termsize;
10955
}
10956
#endif /* defined(TERMSIZE_USE_CONIO) || defined(TERMSIZE_USE_IOCTL) */
10957

10958

10959
/*[clinic input]
10960
os.cpu_count
10961

10962
Return the number of CPUs in the system; return None if indeterminable.
10963

10964
This number is not equivalent to the number of CPUs the current process can
10965
use.  The number of usable CPUs can be obtained with
10966
``len(os.sched_getaffinity(0))``
10967
[clinic start generated code]*/
10968

10969
static PyObject *
10970
os_cpu_count_impl(PyObject *module)
10971
/*[clinic end generated code: output=5fc29463c3936a9c input=e7c8f4ba6dbbadd3]*/
10972
{
10973
    int ncpu = 0;
10974
#ifdef MS_WINDOWS
10975
    SYSTEM_INFO sysinfo;
10976
    GetSystemInfo(&sysinfo);
10977
    ncpu = sysinfo.dwNumberOfProcessors;
10978
#elif defined(__hpux)
10979
    ncpu = mpctl(MPC_GETNUMSPUS, NULL, NULL);
10980
#elif defined(HAVE_SYSCONF) && defined(_SC_NPROCESSORS_ONLN)
10981
    ncpu = sysconf(_SC_NPROCESSORS_ONLN);
inline
           
sysconf will not be inlined into os_cpu_count_impl because its definition is unavailable 
os_cpu_count_impl
10982
#elif defined(__DragonFly__) || \
10983
      defined(__OpenBSD__)   || \
10984
      defined(__FreeBSD__)   || \
10985
      defined(__NetBSD__)    || \
10986
      defined(__APPLE__)
10987
    int mib[2];
10988
    size_t len = sizeof(ncpu);
10989
    mib[0] = CTL_HW;
10990
    mib[1] = HW_NCPU;
10991
    if (sysctl(mib, 2, &ncpu, &len, NULL, 0) != 0)
10992
        ncpu = 0;
10993
#endif
10994
    if (ncpu >= 1)
10995
        return PyLong_FromLong(ncpu);
inline
               
PyLong_FromLong will not be inlined into os_cpu_count_impl because its definition is unavailable 
os_cpu_count_impl
10996
    else
10997
        Py_RETURN_NONE;
gvn
        
load of type i64 not eliminated because it is clobbered by call 
os_cpu_count_impl
gvn
        
load of type i64 not eliminated because it is clobbered by call 
os_cpu_count
10998
}
10999

11000

11001
/*[clinic input]
11002
os.get_inheritable -> bool
11003

11004
    fd: int
11005
    /
11006

11007
Get the close-on-exe flag of the specified file descriptor.
11008
[clinic start generated code]*/
11009

11010
static int
11011
os_get_inheritable_impl(PyObject *module, int fd)
11012
/*[clinic end generated code: output=0445e20e149aa5b8 input=89ac008dc9ab6b95]*/
11013
{
11014
    int return_value;
11015
    _Py_BEGIN_SUPPRESS_IPH
11016
    return_value = _Py_get_inheritable(fd);
inline
                   
_Py_get_inheritable will not be inlined into os_get_inheritable_impl because its definition is unavailable 
os_get_inheritable_impl
11017
    _Py_END_SUPPRESS_IPH
11018
    return return_value;
11019
}
11020

11021

11022
/*[clinic input]
11023
os.set_inheritable
11024
    fd: int
11025
    inheritable: int
11026
    /
11027

11028
Set the inheritable flag of the specified file descriptor.
11029
[clinic start generated code]*/
11030

11031
static PyObject *
11032
os_set_inheritable_impl(PyObject *module, int fd, int inheritable)
11033
/*[clinic end generated code: output=f1b1918a2f3c38c2 input=9ceaead87a1e2402]*/
11034
{
11035
    int result;
11036

11037
    _Py_BEGIN_SUPPRESS_IPH
11038
    result = _Py_set_inheritable(fd, inheritable, NULL);
inline
             
_Py_set_inheritable will not be inlined into os_set_inheritable_impl because its definition is unavailable 
os_set_inheritable_impl
11039
    _Py_END_SUPPRESS_IPH
11040
    if (result < 0)
11041
        return NULL;
11042
    Py_RETURN_NONE;
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_set_inheritable_impl
gvn
    
load of type i64 not eliminated because it is clobbered by call 
os_set_inheritable
11043
}
11044

11045

11046
#ifdef MS_WINDOWS
11047
/*[clinic input]
11048
os.get_handle_inheritable -> bool
11049
    handle: intptr_t
11050
    /
11051

11052
Get the close-on-exe flag of the specified file descriptor.
11053
[clinic start generated code]*/
11054

11055
static int
11056
os_get_handle_inheritable_impl(PyObject *module, intptr_t handle)
11057
/*[clinic end generated code: output=36be5afca6ea84d8 input=cfe99f9c05c70ad1]*/
11058
{
11059
    DWORD flags;
11060

11061
    if (!GetHandleInformation((HANDLE)handle, &flags)) {
11062
        PyErr_SetFromWindowsErr(0);
11063
        return -1;
11064
    }
11065

11066
    return flags & HANDLE_FLAG_INHERIT;
11067
}
11068

11069

11070
/*[clinic input]
11071
os.set_handle_inheritable
11072
    handle: intptr_t
11073
    inheritable: bool
11074
    /
11075

11076
Set the inheritable flag of the specified handle.
11077
[clinic start generated code]*/
11078

11079
static PyObject *
11080
os_set_handle_inheritable_impl(PyObject *module, intptr_t handle,
11081
                               int inheritable)
11082
/*[clinic end generated code: output=021d74fe6c96baa3 input=7a7641390d8364fc]*/
11083
{
11084
    DWORD flags = inheritable ? HANDLE_FLAG_INHERIT : 0;
11085
    if (!SetHandleInformation((HANDLE)handle, HANDLE_FLAG_INHERIT, flags)) {
11086
        PyErr_SetFromWindowsErr(0);
11087
        return NULL;
11088
    }
11089
    Py_RETURN_NONE;
11090
}
11091
#endif /* MS_WINDOWS */
11092

11093
#ifndef MS_WINDOWS
11094
PyDoc_STRVAR(get_blocking__doc__,
11095
    "get_blocking(fd) -> bool\n" \
11096
    "\n" \
11097
    "Get the blocking mode of the file descriptor:\n" \
11098
    "False if the O_NONBLOCK flag is set, True if the flag is cleared.");
11099

11100
static PyObject*
11101
posix_get_blocking(PyObject *self, PyObject *args)
11102
{
11103
    int fd;
11104
    int blocking;
11105

11106
    if (!PyArg_ParseTuple(args, "i:get_blocking", &fd))
inline
         
_PyArg_ParseTuple_SizeT will not be inlined into posix_get_blocking because its definition is unavailable 
posix_get_blocking
11107
        return NULL;
11108

11109
    _Py_BEGIN_SUPPRESS_IPH
11110
    blocking = _Py_get_blocking(fd);
inline
               
_Py_get_blocking will not be inlined into posix_get_blocking because its definition is unavailable 
posix_get_blocking
gvn
                                
load of type i32 not eliminated because it is clobbered by call 
posix_get_blocking
11111
    _Py_END_SUPPRESS_IPH
11112
    if (blocking < 0)
11113
        return NULL;
11114
    return PyBool_FromLong(blocking);
inline
           
PyBool_FromLong will not be inlined into posix_get_blocking because its definition is unavailable 
posix_get_blocking
11115
}
11116

11117
PyDoc_STRVAR(set_blocking__doc__,
11118
    "set_blocking(fd, blocking)\n" \
11119
    "\n" \
11120
    "Set the blocking mode of the specified file descriptor.\n" \
11121
    "Set the O_NONBLOCK flag if blocking is False,\n" \
11122
    "clear the O_NONBLOCK flag otherwise.");
11123

11124
static PyObject*
11125
posix_set_blocking(PyObject *self, PyObject *args)
11126
{
11127
    int fd, blocking, result;
11128

11129
    if (!PyArg_ParseTuple(args, "ii:set_blocking", &fd, &blocking))
inline
         
_PyArg_ParseTuple_SizeT will not be inlined into posix_set_blocking because its definition is unavailable 
posix_set_blocking
11130
        return NULL;
11131

11132
    _Py_BEGIN_SUPPRESS_IPH
11133
    result = _Py_set_blocking(fd, blocking);
inline
             
_Py_set_blocking will not be inlined into posix_set_blocking because its definition is unavailable 
posix_set_blocking
gvn
                              
load of type i32 not eliminated because it is clobbered by call 
posix_set_blocking
gvn
                                  
load of type i32 not eliminated because it is clobbered by call 
posix_set_blocking
11134
    _Py_END_SUPPRESS_IPH
11135
    if (result < 0)
11136
        return NULL;
11137
    Py_RETURN_NONE;
gvn
    
load of type i64 not eliminated because it is clobbered by call 
posix_set_blocking
11138
}
11139
#endif   /* !MS_WINDOWS */
11140

11141

11142
PyDoc_STRVAR(posix_scandir__doc__,
11143
"scandir(path='.') -> iterator of DirEntry objects for given path");
11144

11145
static char *follow_symlinks_keywords[] = {"follow_symlinks", NULL};
11146

11147
typedef struct {
11148
    PyObject_HEAD
11149
    PyObject *name;
11150
    PyObject *path;
11151
    PyObject *stat;
11152
    PyObject *lstat;
11153
#ifdef MS_WINDOWS
11154
    struct _Py_stat_struct win32_lstat;
11155
    __int64 win32_file_index;
11156
    int got_file_index;
11157
#else /* POSIX */
11158
#ifdef HAVE_DIRENT_D_TYPE
11159
    unsigned char d_type;
11160
#endif
11161
    ino_t d_ino;
11162
#endif
11163
} DirEntry;
11164

11165
static void
11166
DirEntry_dealloc(DirEntry *entry)
11167
{
11168
    Py_XDECREF(entry->name);
11169
    Py_XDECREF(entry->path);
gvn
    
load of type %struct._object* not eliminated because it is clobbered by call 
DirEntry_dealloc
11170
    Py_XDECREF(entry->stat);
gvn
    
load of type %struct._object* not eliminated because it is clobbered by call 
DirEntry_dealloc
11171
    Py_XDECREF(entry->lstat);
gvn
    
load of type %struct._object* not eliminated because it is clobbered by call 
DirEntry_dealloc
11172
    Py_TYPE(entry)->tp_free((PyObject *)entry);
gvn
    
load of type %struct._typeobject* not eliminated because it is clobbered by call 
DirEntry_dealloc
11173
}
11174

11175
/* Forward reference */
11176
static int
11177
DirEntry_test_mode(DirEntry *self, int follow_symlinks, unsigned short mode_bits);
11178

11179
/* Set exception and return -1 on error, 0 for False, 1 for True */
11180
static int
11181
DirEntry_is_symlink(DirEntry *self)
11182
{
11183
#ifdef MS_WINDOWS
11184
    return (self->win32_lstat.st_mode & S_IFMT) == S_IFLNK;
11185
#elif defined(HAVE_DIRENT_D_TYPE)
11186
    /* POSIX */
11187
    if (self->d_type != DT_UNKNOWN)
11188
        return self->d_type == DT_LNK;
11189
    else
11190
        return DirEntry_test_mode(self, 0, S_IFLNK);
inline
               
DirEntry_test_mode too costly to inline (cost=465, threshold=250) 
DirEntry_is_symlink
inline
               
DirEntry_test_mode will not be inlined into DirEntry_is_symlink 
DirEntry_is_symlink
inline
               
DirEntry_test_mode too costly to inline (cost=465, threshold=250) 
DirEntry_get_stat
inline
               
DirEntry_test_mode will not be inlined into DirEntry_get_stat 
DirEntry_get_stat
inline
               
DirEntry_test_mode too costly to inline (cost=450, threshold=250) 
DirEntry_py_is_symlink
inline
               
DirEntry_test_mode will not be inlined into DirEntry_py_is_symlink 
DirEntry_py_is_symlink
11191
#else
11192
    /* POSIX without d_type */
11193
    return DirEntry_test_mode(self, 0, S_IFLNK);
11194
#endif
11195
}
11196

11197
static PyObject *
11198
DirEntry_py_is_symlink(DirEntry *self)
11199
{
11200
    int result;
11201

11202
    result = DirEntry_is_symlink(self);
inline
             
DirEntry_is_symlink can be inlined into DirEntry_py_is_symlink with cost=-14970 (threshold=250) 
DirEntry_py_is_symlink
inline
             
DirEntry_is_symlink inlined into DirEntry_py_is_symlink 
DirEntry_py_is_symlink
11203
    if (result == -1)
11204
        return NULL;
11205
    return PyBool_FromLong(result);
inline
           
PyBool_FromLong will not be inlined into DirEntry_py_is_symlink because its definition is unavailable 
DirEntry_py_is_symlink
11206
}
11207

11208
static PyObject *
11209
DirEntry_fetch_stat(DirEntry *self, int follow_symlinks)
11210
{
11211
    int result;
11212
    STRUCT_STAT st;
11213
    PyObject *ub;
11214

11215
#ifdef MS_WINDOWS
11216
    if (PyUnicode_FSDecoder(self->path, &ub)) {
11217
        const wchar_t *path = PyUnicode_AsUnicode(ub);
11218
#else /* POSIX */
11219
    if (PyUnicode_FSConverter(self->path, &ub)) {
inline
        
PyUnicode_FSConverter will not be inlined into DirEntry_fetch_stat because its definition is unavailable 
DirEntry_fetch_stat
gvn
                                    
load of type %struct._object* not eliminated because it is clobbered by call 
DirEntry_get_stat
11220
        const char *path = PyBytes_AS_STRING(ub);
gvn
                           
load of type %struct.PyBytesObject* not eliminated because it is clobbered by call 
DirEntry_fetch_stat
gvn
                           
load of type %struct.PyBytesObject* not eliminated because it is clobbered by call 
DirEntry_get_lstat
gvn
                           
load of type %struct.PyBytesObject* not eliminated because it is clobbered by call 
DirEntry_get_stat
11221
#endif
11222
        if (follow_symlinks)
11223
            result = STAT(path, &st);
inline
                     
stat64 can be inlined into DirEntry_fetch_stat with cost=5 (threshold=487) 
DirEntry_fetch_stat
inline
                     
stat64 inlined into DirEntry_fetch_stat 
DirEntry_fetch_stat
11224
        else
11225
            result = LSTAT(path, &st);
inline
                     
lstat64 can be inlined into DirEntry_fetch_stat with cost=5 (threshold=487) 
DirEntry_fetch_stat
inline
                     
lstat64 inlined into DirEntry_fetch_stat 
DirEntry_fetch_stat
11226
        Py_DECREF(ub);
gvn
        
load of type %struct._object* not eliminated because it is clobbered by call 
DirEntry_fetch_stat
gvn
        
load of type %struct._object* not eliminated because it is clobbered by call 
DirEntry_get_lstat
gvn
        
load of type %struct._object* not eliminated because it is clobbered by call 
DirEntry_get_stat
11227
    } else
11228
        return NULL;
11229

11230
    if (result != 0)
11231
        return path_object_error(self->path);
inline
               
path_object_error can be inlined into DirEntry_fetch_stat with cost=-14990 (threshold=375) 
DirEntry_fetch_stat
inline
               
path_object_error inlined into DirEntry_fetch_stat 
DirEntry_fetch_stat
gvn
                                       
load of type %struct._object* not eliminated in favor of load because it is clobbered by call 
DirEntry_fetch_stat
gvn
                                       
load of type %struct._object* not eliminated in favor of load because it is clobbered by call 
DirEntry_get_lstat
gvn
                                       
load of type %struct._object* not eliminated in favor of load because it is clobbered by call 
DirEntry_get_stat
11232

11233
    return _pystat_fromstructstat(&st);
inline
           
_pystat_fromstructstat too costly to inline (cost=645, threshold=625) 
DirEntry_fetch_stat
inline
           
_pystat_fromstructstat will not be inlined into DirEntry_fetch_stat 
DirEntry_fetch_stat
inline
           
_pystat_fromstructstat too costly to inline (cost=645, threshold=625) 
DirEntry_get_lstat
inline
           
_pystat_fromstructstat will not be inlined into DirEntry_get_lstat 
DirEntry_get_lstat
inline
           
_pystat_fromstructstat too costly to inline (cost=645, threshold=625) 
DirEntry_get_stat
inline
           
_pystat_fromstructstat will not be inlined into DirEntry_get_stat 
DirEntry_get_stat
11234
}
11235

11236
static PyObject *
11237
DirEntry_get_lstat(DirEntry *self)
11238
{
11239
    if (!self->lstat) {
11240
#ifdef MS_WINDOWS
11241
        self->lstat = _pystat_fromstructstat(&self->win32_lstat);
11242
#else /* POSIX */
11243
        self->lstat = DirEntry_fetch_stat(self, 0);
inline
                      
DirEntry_fetch_stat can be inlined into DirEntry_get_lstat with cost=220 (threshold=250) 
DirEntry_get_lstat
inline
                      
DirEntry_fetch_stat inlined into DirEntry_get_lstat 
DirEntry_get_lstat
11244
#endif
11245
    }
11246
    Py_XINCREF(self->lstat);
11247
    return self->lstat;
11248
}
11249

11250
static PyObject *
11251
DirEntry_get_stat(DirEntry *self, int follow_symlinks)
11252
{
11253
    if (!follow_symlinks)
11254
        return DirEntry_get_lstat(self);
inline
               
DirEntry_get_lstat too costly to inline (cost=275, threshold=250) 
DirEntry_get_stat
inline
               
DirEntry_get_lstat will not be inlined into DirEntry_get_stat 
DirEntry_get_stat
11255

11256
    if (!self->stat) {
11257
        int result = DirEntry_is_symlink(self);
inline
                     
DirEntry_is_symlink can be inlined into DirEntry_get_stat with cost=30 (threshold=250) 
DirEntry_get_stat
inline
                     
DirEntry_is_symlink inlined into DirEntry_get_stat 
DirEntry_get_stat
11258
        if (result == -1)
11259
            return NULL;
11260
        else if (result)
11261
            self->stat = DirEntry_fetch_stat(self, 1);
inline
                         
DirEntry_fetch_stat can be inlined into DirEntry_get_stat with cost=-14780 (threshold=250) 
DirEntry_get_stat
inline
                         
DirEntry_fetch_stat inlined into DirEntry_get_stat 
DirEntry_get_stat
11262
        else
11263
            self->stat = DirEntry_get_lstat(self);
inline
                         
DirEntry_get_lstat too costly to inline (cost=275, threshold=250) 
DirEntry_get_stat
inline
                         
DirEntry_get_lstat will not be inlined into DirEntry_get_stat 
DirEntry_get_stat
11264
    }
11265

11266
    Py_XINCREF(self->stat);
11267
    return self->stat;
11268
}
11269

11270
static PyObject *
11271
DirEntry_stat(DirEntry *self, PyObject *args, PyObject *kwargs)
11272
{
11273
    int follow_symlinks = 1;
11274

11275
    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|$p:DirEntry.stat",
inline
         
_PyArg_ParseTupleAndKeywords_SizeT will not be inlined into DirEntry_stat because its definition is unavailable 
DirEntry_stat
11276
                                     follow_symlinks_keywords, &follow_symlinks))
11277
        return NULL;
11278

11279
    return DirEntry_get_stat(self, follow_symlinks);
inline
           
DirEntry_get_stat too costly to inline (cost=425, threshold=250) 
DirEntry_stat
inline
           
DirEntry_get_stat will not be inlined into DirEntry_stat 
DirEntry_stat
gvn
                                   
load of type i32 not eliminated in favor of store because it is clobbered by call 
DirEntry_stat
11280
}
11281

11282
/* Set exception and return -1 on error, 0 for False, 1 for True */
11283
static int
11284
DirEntry_test_mode(DirEntry *self, int follow_symlinks, unsigned short mode_bits)
11285
{
11286
    PyObject *stat = NULL;
11287
    PyObject *st_mode = NULL;
11288
    long mode;
11289
    int result;
11290
#if defined(MS_WINDOWS) || defined(HAVE_DIRENT_D_TYPE)
11291
    int is_symlink;
11292
    int need_stat;
11293
#endif
11294
#ifdef MS_WINDOWS
11295
    unsigned long dir_bits;
11296
#endif
11297
    _Py_IDENTIFIER(st_mode);
11298

11299
#ifdef MS_WINDOWS
11300
    is_symlink = (self->win32_lstat.st_mode & S_IFMT) == S_IFLNK;
11301
    need_stat = follow_symlinks && is_symlink;
11302
#elif defined(HAVE_DIRENT_D_TYPE)
11303
    is_symlink = self->d_type == DT_LNK;
11304
    need_stat = self->d_type == DT_UNKNOWN || (follow_symlinks && is_symlink);
11305
#endif
11306

11307
#if defined(MS_WINDOWS) || defined(HAVE_DIRENT_D_TYPE)
11308
    if (need_stat) {
11309
#endif
11310
        stat = DirEntry_get_stat(self, follow_symlinks);
inline
               
DirEntry_get_stat too costly to inline (cost=400, threshold=250) 
DirEntry_test_mode
inline
               
DirEntry_get_stat will not be inlined into DirEntry_test_mode 
DirEntry_test_mode
11311
        if (!stat) {
11312
            if (PyErr_ExceptionMatches(PyExc_FileNotFoundError)) {
inline
                
PyErr_ExceptionMatches will not be inlined into DirEntry_test_mode because its definition is unavailable 
DirEntry_test_mode
gvn
                                       
load of type %struct._object* not eliminated because it is clobbered by call 
DirEntry_test_mode
11313
                /* If file doesn't exist (anymore), then return False
11314
                   (i.e., say it's not a file/directory) */
11315
                PyErr_Clear();
inline
                
PyErr_Clear will not be inlined into DirEntry_test_mode because its definition is unavailable 
DirEntry_test_mode
11316
                return 0;
11317
            }
11318
            goto error;
11319
        }
11320
        st_mode = _PyObject_GetAttrId(stat, &PyId_st_mode);
inline
                  
_PyObject_GetAttrId will not be inlined into DirEntry_test_mode because its definition is unavailable 
DirEntry_test_mode
11321
        if (!st_mode)
11322
            goto error;
11323

11324
        mode = PyLong_AsLong(st_mode);
inline
               
PyLong_AsLong will not be inlined into DirEntry_test_mode because its definition is unavailable 
DirEntry_test_mode
11325
        if (mode == -1 && PyErr_Occurred())
inline
                          
PyErr_Occurred will not be inlined into DirEntry_test_mode because its definition is unavailable 
DirEntry_test_mode
11326
            goto error;
11327
        Py_CLEAR(st_mode);
gvn
        
load of type i64 not eliminated because it is clobbered by call 
DirEntry_test_mode
11328
        Py_CLEAR(stat);
gvn
        
load of type i64 not eliminated because it is clobbered by store 
DirEntry_test_mode
11329
        result = (mode & S_IFMT) == mode_bits;
11330
#if defined(MS_WINDOWS) || defined(HAVE_DIRENT_D_TYPE)
11331
    }
11332
    else if (is_symlink) {
11333
        assert(mode_bits != S_IFLNK);
11334
        result = 0;
11335
    }
11336
    else {
11337
        assert(mode_bits == S_IFDIR || mode_bits == S_IFREG);
11338
#ifdef MS_WINDOWS
11339
        dir_bits = self->win32_lstat.st_file_attributes & FILE_ATTRIBUTE_DIRECTORY;
11340
        if (mode_bits == S_IFDIR)
11341
            result = dir_bits != 0;
11342
        else
11343
            result = dir_bits == 0;
11344
#else /* POSIX */
11345
        if (mode_bits == S_IFDIR)
11346
            result = self->d_type == DT_DIR;
11347
        else
11348
            result = self->d_type == DT_REG;
11349
#endif
11350
    }
11351
#endif
11352

11353
    return result;
11354

11355
error:
11356
    Py_XDECREF(st_mode);
gvn
    
load of type i64 not eliminated because it is clobbered by call 
DirEntry_test_mode
11357
    Py_XDECREF(stat);
gvn
    
load of type i64 not eliminated because it is clobbered by store 
DirEntry_test_mode
11358
    return -1;
11359
}
11360

11361
static PyObject *
11362
DirEntry_py_test_mode(DirEntry *self, int follow_symlinks, unsigned short mode_bits)
11363
{
11364
    int result;
11365

11366
    result = DirEntry_test_mode(self, follow_symlinks, mode_bits);
inline
             
DirEntry_test_mode too costly to inline (cost=480, threshold=250) 
DirEntry_py_test_mode
inline
             
DirEntry_test_mode will not be inlined into DirEntry_py_test_mode 
DirEntry_py_test_mode
inline
             
DirEntry_test_mode too costly to inline (cost=460, threshold=250) 
DirEntry_is_dir
inline
             
DirEntry_test_mode will not be inlined into DirEntry_is_dir 
DirEntry_is_dir
inline
             
DirEntry_test_mode too costly to inline (cost=460, threshold=250) 
DirEntry_is_file
inline
             
DirEntry_test_mode will not be inlined into DirEntry_is_file 
DirEntry_is_file
11367
    if (result == -1)
11368
        return NULL;
11369
    return PyBool_FromLong(result);
inline
           
PyBool_FromLong will not be inlined into DirEntry_py_test_mode because its definition is unavailable 
DirEntry_py_test_mode
11370
}
11371

11372
static PyObject *
11373
DirEntry_is_dir(DirEntry *self, PyObject *args, PyObject *kwargs)
11374
{
11375
    int follow_symlinks = 1;
11376

11377
    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|$p:DirEntry.is_dir",
inline
         
_PyArg_ParseTupleAndKeywords_SizeT will not be inlined into DirEntry_is_dir because its definition is unavailable 
DirEntry_is_dir
11378
                                     follow_symlinks_keywords, &follow_symlinks))
11379
        return NULL;
11380

11381
    return DirEntry_py_test_mode(self, follow_symlinks, S_IFDIR);
inline
           
DirEntry_py_test_mode can be inlined into DirEntry_is_dir with cost=50 (threshold=250) 
DirEntry_is_dir
inline
           
DirEntry_py_test_mode inlined into DirEntry_is_dir 
DirEntry_is_dir
gvn
                                       
load of type i32 not eliminated in favor of store because it is clobbered by call 
DirEntry_is_dir
11382
}
11383

11384
static PyObject *
11385
DirEntry_is_file(DirEntry *self, PyObject *args, PyObject *kwargs)
11386
{
11387
    int follow_symlinks = 1;
11388

11389
    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|$p:DirEntry.is_file",
inline
         
_PyArg_ParseTupleAndKeywords_SizeT will not be inlined into DirEntry_is_file because its definition is unavailable 
DirEntry_is_file
11390
                                     follow_symlinks_keywords, &follow_symlinks))
11391
        return NULL;
11392

11393
    return DirEntry_py_test_mode(self, follow_symlinks, S_IFREG);
inline
           
DirEntry_py_test_mode can be inlined into DirEntry_is_file with cost=-14950 (threshold=250) 
DirEntry_is_file
inline
           
DirEntry_py_test_mode inlined into DirEntry_is_file 
DirEntry_is_file
gvn
                                       
load of type i32 not eliminated in favor of store because it is clobbered by call 
DirEntry_is_file
11394
}
11395

11396
static PyObject *
11397
DirEntry_inode(DirEntry *self)
11398
{
11399
#ifdef MS_WINDOWS
11400
    if (!self->got_file_index) {
11401
        PyObject *unicode;
11402
        const wchar_t *path;
11403
        STRUCT_STAT stat;
11404
        int result;
11405

11406
        if (!PyUnicode_FSDecoder(self->path, &unicode))
11407
            return NULL;
11408
        path = PyUnicode_AsUnicode(unicode);
11409
        result = LSTAT(path, &stat);
11410
        Py_DECREF(unicode);
11411

11412
        if (result != 0)
11413
            return path_object_error(self->path);
11414

11415
        self->win32_file_index = stat.st_ino;
11416
        self->got_file_index = 1;
11417
    }
11418
    return PyLong_FromLongLong((long long)self->win32_file_index);
11419
#else /* POSIX */
11420
#ifdef HAVE_LARGEFILE_SUPPORT
11421
    return PyLong_FromLongLong((long long)self->d_ino);
11422
#else
11423
    return PyLong_FromLong((long)self->d_ino);
inline
           
PyLong_FromLong will not be inlined into DirEntry_inode because its definition is unavailable 
DirEntry_inode
11424
#endif
11425
#endif
11426
}
11427

11428
static PyObject *
11429
DirEntry_repr(DirEntry *self)
11430
{
11431
    return PyUnicode_FromFormat("<DirEntry %R>", self->name);
inline
           
PyUnicode_FromFormat will not be inlined into DirEntry_repr because its definition is unavailable 
DirEntry_repr
11432
}
11433

11434
static PyObject *
11435
DirEntry_fspath(DirEntry *self)
11436
{
11437
    Py_INCREF(self->path);
11438
    return self->path;
11439
}
11440

11441
static PyMemberDef DirEntry_members[] = {
11442
    {"name", T_OBJECT_EX, offsetof(DirEntry, name), READONLY,
11443
     "the entry's base filename, relative to scandir() \"path\" argument"},
11444
    {"path", T_OBJECT_EX, offsetof(DirEntry, path), READONLY,
11445
     "the entry's full path name; equivalent to os.path.join(scandir_path, entry.name)"},
11446
    {NULL}
11447
};
11448

11449
static PyMethodDef DirEntry_methods[] = {
11450
    {"is_dir", (PyCFunction)DirEntry_is_dir, METH_VARARGS | METH_KEYWORDS,
11451
     "return True if the entry is a directory; cached per entry"
11452
    },
11453
    {"is_file", (PyCFunction)DirEntry_is_file, METH_VARARGS | METH_KEYWORDS,
11454
     "return True if the entry is a file; cached per entry"
11455
    },
11456
    {"is_symlink", (PyCFunction)DirEntry_py_is_symlink, METH_NOARGS,
11457
     "return True if the entry is a symbolic link; cached per entry"
11458
    },
11459
    {"stat", (PyCFunction)DirEntry_stat, METH_VARARGS | METH_KEYWORDS,
11460
     "return stat_result object for the entry; cached per entry"
11461
    },
11462
    {"inode", (PyCFunction)DirEntry_inode, METH_NOARGS,
11463
     "return inode of the entry; cached per entry",
11464
    },
11465
    {"__fspath__", (PyCFunction)DirEntry_fspath, METH_NOARGS,
11466
     "returns the path for the entry",
11467
    },
11468
    {NULL}
11469
};
11470

11471
static PyTypeObject DirEntryType = {
11472
    PyVarObject_HEAD_INIT(NULL, 0)
11473
    MODNAME ".DirEntry",                    /* tp_name */
11474
    sizeof(DirEntry),                       /* tp_basicsize */
11475
    0,                                      /* tp_itemsize */
11476
    /* methods */
11477
    (destructor)DirEntry_dealloc,           /* tp_dealloc */
11478
    0,                                      /* tp_print */
11479
    0,                                      /* tp_getattr */
11480
    0,                                      /* tp_setattr */
11481
    0,                                      /* tp_compare */
11482
    (reprfunc)DirEntry_repr,                /* tp_repr */
11483
    0,                                      /* tp_as_number */
11484
    0,                                      /* tp_as_sequence */
11485
    0,                                      /* tp_as_mapping */
11486
    0,                                      /* tp_hash */
11487
    0,                                      /* tp_call */
11488
    0,                                      /* tp_str */
11489
    0,                                      /* tp_getattro */
11490
    0,                                      /* tp_setattro */
11491
    0,                                      /* tp_as_buffer */
11492
    Py_TPFLAGS_DEFAULT,                     /* tp_flags */
11493
    0,                                      /* tp_doc */
11494
    0,                                      /* tp_traverse */
11495
    0,                                      /* tp_clear */
11496
    0,                                      /* tp_richcompare */
11497
    0,                                      /* tp_weaklistoffset */
11498
    0,                                      /* tp_iter */
11499
    0,                                      /* tp_iternext */
11500
    DirEntry_methods,                       /* tp_methods */
11501
    DirEntry_members,                       /* tp_members */
11502
};
11503

11504
#ifdef MS_WINDOWS
11505

11506
static wchar_t *
11507
join_path_filenameW(const wchar_t *path_wide, const wchar_t *filename)
11508
{
11509
    Py_ssize_t path_len;
11510
    Py_ssize_t size;
11511
    wchar_t *result;
11512
    wchar_t ch;
11513

11514
    if (!path_wide) { /* Default arg: "." */
11515
        path_wide = L".";
11516
        path_len = 1;
11517
    }
11518
    else {
11519
        path_len = wcslen(path_wide);
11520
    }
11521

11522
    /* The +1's are for the path separator and the NUL */
11523
    size = path_len + 1 + wcslen(filename) + 1;
11524
    result = PyMem_New(wchar_t, size);
11525
    if (!result) {
11526
        PyErr_NoMemory();
11527
        return NULL;
11528
    }
11529
    wcscpy(result, path_wide);
11530
    if (path_len > 0) {
11531
        ch = result[path_len - 1];
11532
        if (ch != SEP && ch != ALTSEP && ch != L':')
11533
            result[path_len++] = SEP;
11534
        wcscpy(result + path_len, filename);
11535
    }
11536
    return result;
11537
}
11538

11539
static PyObject *
11540
DirEntry_from_find_data(path_t *path, WIN32_FIND_DATAW *dataW)
11541
{
11542
    DirEntry *entry;
11543
    BY_HANDLE_FILE_INFORMATION file_info;
11544
    ULONG reparse_tag;
11545
    wchar_t *joined_path;
11546

11547
    entry = PyObject_New(DirEntry, &DirEntryType);
11548
    if (!entry)
11549
        return NULL;
11550
    entry->name = NULL;
11551
    entry->path = NULL;
11552
    entry->stat = NULL;
11553
    entry->lstat = NULL;
11554
    entry->got_file_index = 0;
11555

11556
    entry->name = PyUnicode_FromWideChar(dataW->cFileName, -1);
11557
    if (!entry->name)
11558
        goto error;
11559
    if (path->narrow) {
11560
        Py_SETREF(entry->name, PyUnicode_EncodeFSDefault(entry->name));
11561
        if (!entry->name)
11562
            goto error;
11563
    }
11564

11565
    joined_path = join_path_filenameW(path->wide, dataW->cFileName);
11566
    if (!joined_path)
11567
        goto error;
11568

11569
    entry->path = PyUnicode_FromWideChar(joined_path, -1);
11570
    PyMem_Free(joined_path);
11571
    if (!entry->path)
11572
        goto error;
11573
    if (path->narrow) {
11574
        Py_SETREF(entry->path, PyUnicode_EncodeFSDefault(entry->path));
11575
        if (!entry->path)
11576
            goto error;
11577
    }
11578

11579
    find_data_to_file_info(dataW, &file_info, &reparse_tag);
11580
    _Py_attribute_data_to_stat(&file_info, reparse_tag, &entry->win32_lstat);
11581

11582
    return (PyObject *)entry;
11583

11584
error:
11585
    Py_DECREF(entry);
11586
    return NULL;
11587
}
11588

11589
#else /* POSIX */
11590

11591
static char *
11592
join_path_filename(const char *path_narrow, const char* filename, Py_ssize_t filename_len)
11593
{
11594
    Py_ssize_t path_len;
11595
    Py_ssize_t size;
11596
    char *result;
11597

11598
    if (!path_narrow) { /* Default arg: "." */
11599
        path_narrow = ".";
11600
        path_len = 1;
11601
    }
11602
    else {
11603
        path_len = strlen(path_narrow);
inline
                   
strlen will not be inlined into join_path_filename because its definition is unavailable 
join_path_filename
11604
    }
11605

11606
    if (filename_len == -1)
11607
        filename_len = strlen(filename);
inline
                       
strlen will not be inlined into join_path_filename because its definition is unavailable 
join_path_filename
11608

11609
    /* The +1's are for the path separator and the NUL */
11610
    size = path_len + 1 + filename_len + 1;
11611
    result = PyMem_New(char, size);
inline
             
PyMem_Malloc will not be inlined into join_path_filename because its definition is unavailable 
join_path_filename
11612
    if (!result) {
11613
        PyErr_NoMemory();
inline
        
PyErr_NoMemory will not be inlined into join_path_filename because its definition is unavailable 
join_path_filename
11614
        return NULL;
11615
    }
11616
    strcpy(result, path_narrow);
inline
    
strcpy will not be inlined into join_path_filename because its definition is unavailable 
join_path_filename
11617
    if (path_len > 0 && result[path_len - 1] != '/')
gvn
                        
load of type i8 not eliminated because it is clobbered by call 
join_path_filename
gvn
                        
load of type i8 not eliminated because it is clobbered by call 
DirEntry_from_posix_info
gvn
                        
load of type i8 not eliminated because it is clobbered by call 
ScandirIterator_iternext
11618
        result[path_len++] = '/';
11619
    strcpy(result + path_len, filename);
inline
    
strcpy will not be inlined into join_path_filename because its definition is unavailable 
join_path_filename
11620
    return result;
11621
}
11622

11623
static PyObject *
11624
DirEntry_from_posix_info(path_t *path, const char *name, Py_ssize_t name_len,
11625
                         ino_t d_ino
11626
#ifdef HAVE_DIRENT_D_TYPE
11627
                         , unsigned char d_type
11628
#endif
11629
                         )
11630
{
11631
    DirEntry *entry;
11632
    char *joined_path;
11633

11634
    entry = PyObject_New(DirEntry, &DirEntryType);
inline
            
_PyObject_New will not be inlined into DirEntry_from_posix_info because its definition is unavailable 
DirEntry_from_posix_info
11635
    if (!entry)
11636
        return NULL;
11637
    entry->name = NULL;
11638
    entry->path = NULL;
11639
    entry->stat = NULL;
11640
    entry->lstat = NULL;
11641

11642
    joined_path = join_path_filename(path->narrow, name, name_len);
inline
                  
join_path_filename can be inlined into DirEntry_from_posix_info with cost=-14725 (threshold=250) 
DirEntry_from_posix_info
inline
                  
join_path_filename inlined into DirEntry_from_posix_info 
DirEntry_from_posix_info
gvn
                                           
load of type i8* not eliminated because it is clobbered by call 
DirEntry_from_posix_info
gvn
                                           
load of type i8* not eliminated because it is clobbered by call 
ScandirIterator_iternext
11643
    if (!joined_path)
11644
        goto error;
11645

11646
    if (!path->narrow || !PyBytes_Check(path->object)) {
gvn
               
load of type i8* not eliminated in favor of load because it is clobbered by call 
DirEntry_from_posix_info
gvn
                          
load of type %struct._object* not eliminated because it is clobbered by call 
DirEntry_from_posix_info
gvn
               
load of type i8* not eliminated in favor of load because it is clobbered by call 
ScandirIterator_iternext
gvn
                          
load of type %struct._object* not eliminated because it is clobbered by call 
ScandirIterator_iternext
11647
        entry->name = PyUnicode_DecodeFSDefaultAndSize(name, name_len);
inline
                      
PyUnicode_DecodeFSDefaultAndSize will not be inlined into DirEntry_from_posix_info because its definition is unavailable 
DirEntry_from_posix_info
11648
        entry->path = PyUnicode_DecodeFSDefault(joined_path);
inline
                      
PyUnicode_DecodeFSDefault will not be inlined into DirEntry_from_posix_info because its definition is unavailable 
DirEntry_from_posix_info
11649
    }
11650
    else {
11651
        entry->name = PyBytes_FromStringAndSize(name, name_len);
inline
                      
PyBytes_FromStringAndSize will not be inlined into DirEntry_from_posix_info because its definition is unavailable 
DirEntry_from_posix_info
11652
        entry->path = PyBytes_FromString(joined_path);
inline
                      
PyBytes_FromString will not be inlined into DirEntry_from_posix_info because its definition is unavailable 
DirEntry_from_posix_info
11653
    }
11654
    PyMem_Free(joined_path);
inline
    
PyMem_Free will not be inlined into DirEntry_from_posix_info because its definition is unavailable 
DirEntry_from_posix_info
11655
    if (!entry->name || !entry->path)
gvn
                
load of type %struct._object* not eliminated in favor of store because it is clobbered by call 
DirEntry_from_posix_info
gvn
                                
load of type %struct._object* not eliminated because it is clobbered by call 
DirEntry_from_posix_info
gvn
                
load of type %struct._object* not eliminated because it is clobbered by call 
ScandirIterator_iternext
gvn
                                
load of type %struct._object* not eliminated in favor of store because it is clobbered by call 
ScandirIterator_iternext
11656
        goto error;
11657

11658
#ifdef HAVE_DIRENT_D_TYPE
11659
    entry->d_type = d_type;
11660
#endif
11661
    entry->d_ino = d_ino;
11662

11663
    return (PyObject *)entry;
11664

11665
error:
11666
    Py_XDECREF(entry);
gvn
    
load of type i64 not eliminated because it is clobbered by call 
DirEntry_from_posix_info
gvn
    
load of type i64 not eliminated because it is clobbered by call 
ScandirIterator_iternext
11667
    return NULL;
11668
}
11669

11670
#endif
11671

11672

11673
typedef struct {
11674
    PyObject_HEAD
11675
    path_t path;
11676
#ifdef MS_WINDOWS
11677
    HANDLE handle;
11678
    WIN32_FIND_DATAW file_data;
11679
    int first_time;
11680
#else /* POSIX */
11681
    DIR *dirp;
11682
#endif
11683
} ScandirIterator;
11684

11685
#ifdef MS_WINDOWS
11686

11687
static int
11688
ScandirIterator_is_closed(ScandirIterator *iterator)
11689
{
11690
    return iterator->handle == INVALID_HANDLE_VALUE;
11691
}
11692

11693
static void
11694
ScandirIterator_closedir(ScandirIterator *iterator)
11695
{
11696
    HANDLE handle = iterator->handle;
11697

11698
    if (handle == INVALID_HANDLE_VALUE)
11699
        return;
11700

11701
    iterator->handle = INVALID_HANDLE_VALUE;
11702
    Py_BEGIN_ALLOW_THREADS
11703
    FindClose(handle);
11704
    Py_END_ALLOW_THREADS
11705
}
11706

11707
static PyObject *
11708
ScandirIterator_iternext(ScandirIterator *iterator)
11709
{
11710
    WIN32_FIND_DATAW *file_data = &iterator->file_data;
11711
    BOOL success;
11712
    PyObject *entry;
11713

11714
    /* Happens if the iterator is iterated twice, or closed explicitly */
11715
    if (iterator->handle == INVALID_HANDLE_VALUE)
11716
        return NULL;
11717

11718
    while (1) {
11719
        if (!iterator->first_time) {
11720
            Py_BEGIN_ALLOW_THREADS
11721
            success = FindNextFileW(iterator->handle, file_data);
11722
            Py_END_ALLOW_THREADS
11723
            if (!success) {
11724
                /* Error or no more files */
11725
                if (GetLastError() != ERROR_NO_MORE_FILES)
11726
                    path_error(&iterator->path);
11727
                break;
11728
            }
11729
        }
11730
        iterator->first_time = 0;
11731

11732
        /* Skip over . and .. */
11733
        if (wcscmp(file_data->cFileName, L".") != 0 &&
11734
            wcscmp(file_data->cFileName, L"..") != 0) {
11735
            entry = DirEntry_from_find_data(&iterator->path, file_data);
11736
            if (!entry)
11737
                break;
11738
            return entry;
11739
        }
11740

11741
        /* Loop till we get a non-dot directory or finish iterating */
11742
    }
11743

11744
    /* Error or no more files */
11745
    ScandirIterator_closedir(iterator);
11746
    return NULL;
11747
}
11748

11749
#else /* POSIX */
11750

11751
static int
11752
ScandirIterator_is_closed(ScandirIterator *iterator)
11753
{
11754
    return !iterator->dirp;
11755
}
11756

11757
static void
11758
ScandirIterator_closedir(ScandirIterator *iterator)
11759
{
11760
    DIR *dirp = iterator->dirp;
gvn
                          
load of type %struct.__dirstream* not eliminated because it is clobbered by call 
ScandirIterator_iternext
11761

11762
    if (!dirp)
11763
        return;
11764

11765
    iterator->dirp = NULL;
11766
    Py_BEGIN_ALLOW_THREADS
inline
    
PyEval_SaveThread will not be inlined into ScandirIterator_closedir because its definition is unavailable 
ScandirIterator_closedir
11767
    closedir(dirp);
inline
    
closedir will not be inlined into ScandirIterator_closedir because its definition is unavailable 
ScandirIterator_closedir
11768
    Py_END_ALLOW_THREADS
inline
    
PyEval_RestoreThread will not be inlined into ScandirIterator_closedir because its definition is unavailable 
ScandirIterator_closedir
11769
    return;
11770
}
11771

11772
static PyObject *
11773
ScandirIterator_iternext(ScandirIterator *iterator)
11774
{
11775
    struct dirent *direntp;
11776
    Py_ssize_t name_len;
11777
    int is_dot;
11778
    PyObject *entry;
11779

11780
    /* Happens if the iterator is iterated twice, or closed explicitly */
11781
    if (!iterator->dirp)
11782
        return NULL;
11783

11784
    while (1) {
loop-vectorize
    
loop not vectorized: loop control flow is not understood by vectorizer 
ScandirIterator_iternext
loop-vectorize
    
loop not vectorized 
ScandirIterator_iternext
11785
        errno = 0;
inline
        
__errno_location will not be inlined into ScandirIterator_iternext because its definition is unavailable 
ScandirIterator_iternext
11786
        Py_BEGIN_ALLOW_THREADS
inline
        
PyEval_SaveThread will not be inlined into ScandirIterator_iternext because its definition is unavailable 
ScandirIterator_iternext
11787
        direntp = readdir(iterator->dirp);
inline
                  
readdir64 will not be inlined into ScandirIterator_iternext because its definition is unavailable 
ScandirIterator_iternext
licm
                                    
failed to move load with loop-invariant address because the loop may invalidate its value 
ScandirIterator_iternext
gvn
                                    
load of type %struct.__dirstream* not eliminated in favor of load because it is clobbered by call 
ScandirIterator_iternext
11788
        Py_END_ALLOW_THREADS
inline
        
PyEval_RestoreThread will not be inlined into ScandirIterator_iternext because its definition is unavailable 
ScandirIterator_iternext
11789

11790
        if (!direntp) {
11791
            /* Error or no more files */
11792
            if (errno != 0)
gvn
                
load of type i32 not eliminated in favor of store because it is clobbered by call 
ScandirIterator_iternext
11793
                path_error(&iterator->path);
inline
                
path_error can be inlined into ScandirIterator_iternext with cost=-14990 (threshold=375) 
ScandirIterator_iternext
inline
                
path_error inlined into ScandirIterator_iternext 
ScandirIterator_iternext
11794
            break;
11795
        }
11796

11797
        /* Skip over . and .. */
11798
        name_len = NAMLEN(direntp);
inline
                   
strlen will not be inlined into ScandirIterator_iternext because its definition is unavailable 
ScandirIterator_iternext
11799
        is_dot = direntp->d_name[0] == '.' &&
11800
                 (name_len == 1 || (direntp->d_name[1] == '.' && name_len == 2));
11801
        if (!is_dot) {
11802
            entry = DirEntry_from_posix_info(&iterator->path, direntp->d_name,
inline
                    
DirEntry_from_posix_info can be inlined into ScandirIterator_iternext with cost=-14350 (threshold=250) 
ScandirIterator_iternext
inline
                    
DirEntry_from_posix_info inlined into ScandirIterator_iternext 
ScandirIterator_iternext
11803
                                            name_len, direntp->d_ino
11804
#ifdef HAVE_DIRENT_D_TYPE
11805
                                            , direntp->d_type
11806
#endif
11807
                                            );
11808
            if (!entry)
11809
                break;
11810
            return entry;
11811
        }
11812

11813
        /* Loop till we get a non-dot directory or finish iterating */
11814
    }
11815

11816
    /* Error or no more files */
11817
    ScandirIterator_closedir(iterator);
inline
    
ScandirIterator_closedir can be inlined into ScandirIterator_iternext with cost=85 (threshold=250) 
ScandirIterator_iternext
inline
    
ScandirIterator_closedir inlined into ScandirIterator_iternext 
ScandirIterator_iternext
11818
    return NULL;
11819
}
11820

11821
#endif
11822

11823
static PyObject *
11824
ScandirIterator_close(ScandirIterator *self, PyObject *args)
11825
{
11826
    ScandirIterator_closedir(self);
inline
    
ScandirIterator_closedir can be inlined into ScandirIterator_close with cost=-14915 (threshold=250) 
ScandirIterator_close
inline
    
ScandirIterator_closedir inlined into ScandirIterator_close 
ScandirIterator_close
11827
    Py_RETURN_NONE;
gvn
    
load of type i64 not eliminated because it is clobbered by call 
ScandirIterator_close
11828
}
11829

11830
static PyObject *
11831
ScandirIterator_enter(PyObject *self, PyObject *args)
11832
{
11833
    Py_INCREF(self);
11834
    return self;
11835
}
11836

11837
static PyObject *
11838
ScandirIterator_exit(ScandirIterator *self, PyObject *args)
11839
{
11840
    ScandirIterator_closedir(self);
inline
    
ScandirIterator_closedir can be inlined into ScandirIterator_exit with cost=85 (threshold=250) 
ScandirIterator_exit
inline
    
ScandirIterator_closedir inlined into ScandirIterator_exit 
ScandirIterator_exit
11841
    Py_RETURN_NONE;
gvn
    
load of type i64 not eliminated because it is clobbered by call 
ScandirIterator_exit
11842
}
11843

11844
static void
11845
ScandirIterator_finalize(ScandirIterator *iterator)
11846
{
11847
    PyObject *error_type, *error_value, *error_traceback;
11848

11849
    /* Save the current exception, if any. */
11850
    PyErr_Fetch(&error_type, &error_value, &error_traceback);
inline
    
PyErr_Fetch will not be inlined into ScandirIterator_finalize because its definition is unavailable 
ScandirIterator_finalize
11851

11852
    if (!ScandirIterator_is_closed(iterator)) {
inline
         
ScandirIterator_is_closed can be inlined into ScandirIterator_finalize with cost=-15030 (threshold=375) 
ScandirIterator_finalize
inline
         
ScandirIterator_is_closed inlined into ScandirIterator_finalize 
ScandirIterator_finalize
11853
        ScandirIterator_closedir(iterator);
inline
        
ScandirIterator_closedir can be inlined into ScandirIterator_finalize with cost=85 (threshold=250) 
ScandirIterator_finalize
inline
        
ScandirIterator_closedir inlined into ScandirIterator_finalize 
ScandirIterator_finalize
11854

11855
        if (PyErr_ResourceWarning((PyObject *)iterator, 1,
inline
            
PyErr_ResourceWarning will not be inlined into ScandirIterator_finalize because its definition is unavailable 
ScandirIterator_finalize
11856
                                  "unclosed scandir iterator %R", iterator)) {
11857
            /* Spurious errors can appear at shutdown */
11858
            if (PyErr_ExceptionMatches(PyExc_Warning)) {
inline
                
PyErr_ExceptionMatches will not be inlined into ScandirIterator_finalize because its definition is unavailable 
ScandirIterator_finalize
gvn
                                       
load of type %struct._object* not eliminated because it is clobbered by call 
ScandirIterator_finalize
11859
                PyErr_WriteUnraisable((PyObject *) iterator);
inline
                
PyErr_WriteUnraisable will not be inlined into ScandirIterator_finalize because its definition is unavailable 
ScandirIterator_finalize
11860
            }
11861
        }
11862
    }
11863

11864
    Py_CLEAR(iterator->path.object);
gvn
    
load of type %struct._object* not eliminated because it is clobbered by call 
ScandirIterator_finalize
11865
    path_cleanup(&iterator->path);
inline
    
path_cleanup can be inlined into ScandirIterator_finalize with cost=-14970 (threshold=250) 
ScandirIterator_finalize
inline
    
path_cleanup inlined into ScandirIterator_finalize 
ScandirIterator_finalize
11866

11867
    /* Restore the saved exception. */
11868
    PyErr_Restore(error_type, error_value, error_traceback);
inline
    
PyErr_Restore will not be inlined into ScandirIterator_finalize because its definition is unavailable 
ScandirIterator_finalize
gvn
                  
load of type %struct._object* not eliminated because it is clobbered by call 
ScandirIterator_finalize
gvn
                              
load of type %struct._object* not eliminated because it is clobbered by call 
ScandirIterator_finalize
gvn
                                           
load of type %struct._object* not eliminated because it is clobbered by call 
ScandirIterator_finalize
11869
}
11870

11871
static void
11872
ScandirIterator_dealloc(ScandirIterator *iterator)
11873
{
11874
    if (PyObject_CallFinalizerFromDealloc((PyObject *)iterator) < 0)
inline
        
PyObject_CallFinalizerFromDealloc will not be inlined into ScandirIterator_dealloc because its definition is unavailable 
ScandirIterator_dealloc
11875
        return;
11876

11877
    Py_TYPE(iterator)->tp_free((PyObject *)iterator);
gvn
    
load of type %struct._typeobject* not eliminated because it is clobbered by call 
ScandirIterator_dealloc
11878
}
11879

11880
static PyMethodDef ScandirIterator_methods[] = {
11881
    {"__enter__", (PyCFunction)ScandirIterator_enter, METH_NOARGS},
11882
    {"__exit__", (PyCFunction)ScandirIterator_exit, METH_VARARGS},
11883
    {"close", (PyCFunction)ScandirIterator_close, METH_NOARGS},
11884
    {NULL}
11885
};
11886

11887
static PyTypeObject ScandirIteratorType = {
11888
    PyVarObject_HEAD_INIT(NULL, 0)
11889
    MODNAME ".ScandirIterator",             /* tp_name */
11890
    sizeof(ScandirIterator),                /* tp_basicsize */
11891
    0,                                      /* tp_itemsize */
11892
    /* methods */
11893
    (destructor)ScandirIterator_dealloc,    /* tp_dealloc */
11894
    0,                                      /* tp_print */
11895
    0,                                      /* tp_getattr */
11896
    0,                                      /* tp_setattr */
11897
    0,                                      /* tp_compare */
11898
    0,                                      /* tp_repr */
11899
    0,                                      /* tp_as_number */
11900
    0,                                      /* tp_as_sequence */
11901
    0,                                      /* tp_as_mapping */
11902
    0,                                      /* tp_hash */
11903
    0,                                      /* tp_call */
11904
    0,                                      /* tp_str */
11905
    0,                                      /* tp_getattro */
11906
    0,                                      /* tp_setattro */
11907
    0,                                      /* tp_as_buffer */
11908
    Py_TPFLAGS_DEFAULT
11909
        | Py_TPFLAGS_HAVE_FINALIZE,         /* tp_flags */
11910
    0,                                      /* tp_doc */
11911
    0,                                      /* tp_traverse */
11912
    0,                                      /* tp_clear */
11913
    0,                                      /* tp_richcompare */
11914
    0,                                      /* tp_weaklistoffset */
11915
    PyObject_SelfIter,                      /* tp_iter */
11916
    (iternextfunc)ScandirIterator_iternext, /* tp_iternext */
11917
    ScandirIterator_methods,                /* tp_methods */
11918
    0,                                      /* tp_members */
11919
    0,                                      /* tp_getset */
11920
    0,                                      /* tp_base */
11921
    0,                                      /* tp_dict */
11922
    0,                                      /* tp_descr_get */
11923
    0,                                      /* tp_descr_set */
11924
    0,                                      /* tp_dictoffset */
11925
    0,                                      /* tp_init */
11926
    0,                                      /* tp_alloc */
11927
    0,                                      /* tp_new */
11928
    0,                                      /* tp_free */
11929
    0,                                      /* tp_is_gc */
11930
    0,                                      /* tp_bases */
11931
    0,                                      /* tp_mro */
11932
    0,                                      /* tp_cache */
11933
    0,                                      /* tp_subclasses */
11934
    0,                                      /* tp_weaklist */
11935
    0,                                      /* tp_del */
11936
    0,                                      /* tp_version_tag */
11937
    (destructor)ScandirIterator_finalize,   /* tp_finalize */
11938
};
11939

11940
static PyObject *
11941
posix_scandir(PyObject *self, PyObject *args, PyObject *kwargs)
11942
{
11943
    ScandirIterator *iterator;
11944
    static char *keywords[] = {"path", NULL};
11945
#ifdef MS_WINDOWS
11946
    wchar_t *path_strW;
11947
#else
11948
    const char *path;
11949
#endif
11950

11951
    iterator = PyObject_New(ScandirIterator, &ScandirIteratorType);
inline
               
_PyObject_New will not be inlined into posix_scandir because its definition is unavailable 
posix_scandir
11952
    if (!iterator)
11953
        return NULL;
11954
    memset(&iterator->path, 0, sizeof(path_t));
11955
    iterator->path.function_name = "scandir";
11956
    iterator->path.nullable = 1;
11957

11958
#ifdef MS_WINDOWS
11959
    iterator->handle = INVALID_HANDLE_VALUE;
11960
#else
11961
    iterator->dirp = NULL;
11962
#endif
11963

11964
    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|O&:scandir", keywords,
inline
         
_PyArg_ParseTupleAndKeywords_SizeT will not be inlined into posix_scandir because its definition is unavailable 
posix_scandir
11965
                                     path_converter, &iterator->path))
11966
        goto error;
11967

11968
    /* path_converter doesn't keep path.object around, so do it
11969
       manually for the lifetime of the iterator here (the refcount
11970
       is decremented in ScandirIterator_dealloc)
11971
    */
11972
    Py_XINCREF(iterator->path.object);
gvn
    
load of type %struct._object* not eliminated because it is clobbered by call 
posix_scandir
11973

11974
#ifdef MS_WINDOWS
11975
    iterator->first_time = 1;
11976

11977
    path_strW = join_path_filenameW(iterator->path.wide, L"*.*");
11978
    if (!path_strW)
11979
        goto error;
11980

11981
    Py_BEGIN_ALLOW_THREADS
11982
    iterator->handle = FindFirstFileW(path_strW, &iterator->file_data);
11983
    Py_END_ALLOW_THREADS
11984

11985
    PyMem_Free(path_strW);
11986

11987
    if (iterator->handle == INVALID_HANDLE_VALUE) {
11988
        path_error(&iterator->path);
11989
        goto error;
11990
    }
11991
#else /* POSIX */
11992
    if (iterator->path.narrow)
gvn
                       
load of type i8* not eliminated because it is clobbered by call 
posix_scandir
11993
        path = iterator->path.narrow;
11994
    else
11995
        path = ".";
11996

11997
    errno = 0;
inline
    
__errno_location will not be inlined into posix_scandir because its definition is unavailable 
posix_scandir
11998
    Py_BEGIN_ALLOW_THREADS
inline
    
PyEval_SaveThread will not be inlined into posix_scandir because its definition is unavailable 
posix_scandir
11999
    iterator->dirp = opendir(path);
inline
                     
opendir will not be inlined into posix_scandir because its definition is unavailable 
posix_scandir
12000
    Py_END_ALLOW_THREADS
inline
    
PyEval_RestoreThread will not be inlined into posix_scandir because its definition is unavailable 
posix_scandir
12001

12002
    if (!iterator->dirp) {
gvn
                   
load of type %struct.__dirstream* not eliminated because it is clobbered by call 
posix_scandir
12003
        path_error(&iterator->path);
inline
        
path_error can be inlined into posix_scandir with cost=10 (threshold=375) 
posix_scandir
inline
        
path_error inlined into posix_scandir 
posix_scandir
12004
        goto error;
12005
    }
12006
#endif
12007

12008
    return (PyObject *)iterator;
12009

12010
error:
12011
    Py_DECREF(iterator);
gvn
    
load of type i64 not eliminated because it is clobbered by call 
posix_scandir
12012
    return NULL;
12013
}
12014

12015
/*
12016
    Return the file system path representation of the object.
12017

12018
    If the object is str or bytes, then allow it to pass through with
12019
    an incremented refcount. If the object defines __fspath__(), then
12020
    return the result of that method. All other types raise a TypeError.
12021
*/
12022
PyObject *
12023
PyOS_FSPath(PyObject *path)
12024
{
12025
    /* For error message reasons, this function is manually inlined in
12026
       path_converter(). */
12027
    _Py_IDENTIFIER(__fspath__);
12028
    PyObject *func = NULL;
12029
    PyObject *path_repr = NULL;
12030

12031
    if (PyUnicode_Check(path) || PyBytes_Check(path)) {
12032
        Py_INCREF(path);
12033
        return path;
12034
    }
12035

12036
    func = _PyObject_LookupSpecial(path, &PyId___fspath__);
inline
           
_PyObject_LookupSpecial will not be inlined into PyOS_FSPath because its definition is unavailable 
PyOS_FSPath
12037
    if (NULL == func) {
12038
        return PyErr_Format(PyExc_TypeError,
inline
               
PyErr_Format will not be inlined into PyOS_FSPath because its definition is unavailable 
PyOS_FSPath
gvn
                            
load of type %struct._object* not eliminated because it is clobbered by call 
PyOS_FSPath
12039
                            "expected str, bytes or os.PathLike object, "
12040
                            "not %.200s",
12041
                            Py_TYPE(path)->tp_name);
gvn
                            
load of type %struct._typeobject* not eliminated in favor of load because it is clobbered by call 
PyOS_FSPath
12042
    }
12043

12044
    path_repr = PyObject_CallFunctionObjArgs(func, NULL);
inline
                
PyObject_CallFunctionObjArgs will not be inlined into PyOS_FSPath because its definition is unavailable 
PyOS_FSPath
12045
    Py_DECREF(func);
gvn
    
load of type i64 not eliminated because it is clobbered by call 
PyOS_FSPath
12046
    if (NULL == path_repr) {
12047
        return NULL;
12048
    }
12049

12050
    if (!(PyUnicode_Check(path_repr) || PyBytes_Check(path_repr))) {
gvn
          
load of type %struct._typeobject* not eliminated because it is clobbered by call 
PyOS_FSPath
12051
        PyErr_Format(PyExc_TypeError,
inline
        
PyErr_Format will not be inlined into PyOS_FSPath because its definition is unavailable 
PyOS_FSPath
gvn
                     
load of type %struct._object* not eliminated because it is clobbered by call 
PyOS_FSPath
12052
                     "expected %.200s.__fspath__() to return str or bytes, "
12053
                     "not %.200s", Py_TYPE(path)->tp_name,
gvn
                                   
load of type %struct._typeobject* not eliminated in favor of load because it is clobbered by call 
PyOS_FSPath
12054
                     Py_TYPE(path_repr)->tp_name);
12055
        Py_DECREF(path_repr);
gvn
        
load of type i64 not eliminated because it is clobbered by call 
PyOS_FSPath
12056
        return NULL;
12057
    }
12058

12059
    return path_repr;
12060
}
12061

12062
/*[clinic input]
12063
os.fspath
12064

12065
    path: object
12066

12067
Return the file system path representation of the object.
12068

12069
If the object is str or bytes, then allow it to pass through as-is. If the
12070
object defines __fspath__(), then return the result of that method. All other
12071
types raise a TypeError.
12072
[clinic start generated code]*/
12073

12074
static PyObject *
12075
os_fspath_impl(PyObject *module, PyObject *path)
12076
/*[clinic end generated code: output=c3c3b78ecff2914f input=e357165f7b22490f]*/
12077
{
12078
    return PyOS_FSPath(path);
inline
           
PyOS_FSPath too costly to inline (cost=350, threshold=250) 
os_fspath_impl
inline
           
PyOS_FSPath will not be inlined into os_fspath_impl 
os_fspath_impl
inline
           
PyOS_FSPath too costly to inline (cost=350, threshold=250) 
os_fspath
inline
           
PyOS_FSPath will not be inlined into os_fspath 
os_fspath
12079
}
12080

12081
#ifdef HAVE_GETRANDOM_SYSCALL
12082
/*[clinic input]
12083
os.getrandom
12084

12085
    size: Py_ssize_t
12086
    flags: int=0
12087

12088
Obtain a series of random bytes.
12089
[clinic start generated code]*/
12090

12091
static PyObject *
12092
os_getrandom_impl(PyObject *module, Py_ssize_t size, int flags)
12093
/*[clinic end generated code: output=b3a618196a61409c input=59bafac39c594947]*/
12094
{
12095
    PyObject *bytes;
12096
    Py_ssize_t n;
12097

12098
    if (size < 0) {
12099
        errno = EINVAL;
12100
        return posix_error();
12101
    }
12102

12103
    bytes = PyBytes_FromStringAndSize(NULL, size);
12104
    if (bytes == NULL) {
12105
        PyErr_NoMemory();
12106
        return NULL;
12107
    }
12108

12109
    while (1) {
12110
        n = syscall(SYS_getrandom,
12111
                    PyBytes_AS_STRING(bytes),
12112
                    PyBytes_GET_SIZE(bytes),
12113
                    flags);
12114
        if (n < 0 && errno == EINTR) {
12115
            if (PyErr_CheckSignals() < 0) {
12116
                goto error;
12117
            }
12118

12119
            /* getrandom() was interrupted by a signal: retry */
12120
            continue;
12121
        }
12122
        break;
12123
    }
12124

12125
    if (n < 0) {
12126
        PyErr_SetFromErrno(PyExc_OSError);
12127
        goto error;
12128
    }
12129

12130
    if (n != size) {
12131
        _PyBytes_Resize(&bytes, n);
12132
    }
12133

12134
    return bytes;
12135

12136
error:
12137
    Py_DECREF(bytes);
12138
    return NULL;
12139
}
12140
#endif   /* HAVE_GETRANDOM_SYSCALL */
12141

12142
#include "clinic/posixmodule.c.h"
12143

12144
/*[clinic input]
12145
dump buffer
12146
[clinic start generated code]*/
12147
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=524ce2e021e4eba6]*/
12148

12149

12150
static PyMethodDef posix_methods[] = {
12151

12152
    OS_STAT_METHODDEF
12153
    OS_ACCESS_METHODDEF
12154
    OS_TTYNAME_METHODDEF
12155
    OS_CHDIR_METHODDEF
12156
    OS_CHFLAGS_METHODDEF
12157
    OS_CHMOD_METHODDEF
12158
    OS_FCHMOD_METHODDEF
12159
    OS_LCHMOD_METHODDEF
12160
    OS_CHOWN_METHODDEF
12161
    OS_FCHOWN_METHODDEF
12162
    OS_LCHOWN_METHODDEF
12163
    OS_LCHFLAGS_METHODDEF
12164
    OS_CHROOT_METHODDEF
12165
    OS_CTERMID_METHODDEF
12166
    OS_GETCWD_METHODDEF
12167
    OS_GETCWDB_METHODDEF
12168
    OS_LINK_METHODDEF
12169
    OS_LISTDIR_METHODDEF
12170
    OS_LSTAT_METHODDEF
12171
    OS_MKDIR_METHODDEF
12172
    OS_NICE_METHODDEF
12173
    OS_GETPRIORITY_METHODDEF
12174
    OS_SETPRIORITY_METHODDEF
12175
#ifdef HAVE_READLINK
12176
    {"readlink",        (PyCFunction)posix_readlink,
12177
                        METH_VARARGS | METH_KEYWORDS,
12178
                        readlink__doc__},
12179
#endif /* HAVE_READLINK */
12180
#if !defined(HAVE_READLINK) && defined(MS_WINDOWS)
12181
    {"readlink",        (PyCFunction)win_readlink,
12182
                        METH_VARARGS | METH_KEYWORDS,
12183
                        readlink__doc__},
12184
#endif /* !defined(HAVE_READLINK) && defined(MS_WINDOWS) */
12185
    OS_RENAME_METHODDEF
12186
    OS_REPLACE_METHODDEF
12187
    OS_RMDIR_METHODDEF
12188
    {"stat_float_times", stat_float_times, METH_VARARGS, stat_float_times__doc__},
12189
    OS_SYMLINK_METHODDEF
12190
    OS_SYSTEM_METHODDEF
12191
    OS_UMASK_METHODDEF
12192
    OS_UNAME_METHODDEF
12193
    OS_UNLINK_METHODDEF
12194
    OS_REMOVE_METHODDEF
12195
    OS_UTIME_METHODDEF
12196
    OS_TIMES_METHODDEF
12197
    OS__EXIT_METHODDEF
12198
    OS_EXECV_METHODDEF
12199
    OS_EXECVE_METHODDEF
12200
    OS_SPAWNV_METHODDEF
12201
    OS_SPAWNVE_METHODDEF
12202
    OS_FORK1_METHODDEF
12203
    OS_FORK_METHODDEF
12204
    OS_SCHED_GET_PRIORITY_MAX_METHODDEF
12205
    OS_SCHED_GET_PRIORITY_MIN_METHODDEF
12206
    OS_SCHED_GETPARAM_METHODDEF
12207
    OS_SCHED_GETSCHEDULER_METHODDEF
12208
    OS_SCHED_RR_GET_INTERVAL_METHODDEF
12209
    OS_SCHED_SETPARAM_METHODDEF
12210
    OS_SCHED_SETSCHEDULER_METHODDEF
12211
    OS_SCHED_YIELD_METHODDEF
12212
    OS_SCHED_SETAFFINITY_METHODDEF
12213
    OS_SCHED_GETAFFINITY_METHODDEF
12214
    OS_OPENPTY_METHODDEF
12215
    OS_FORKPTY_METHODDEF
12216
    OS_GETEGID_METHODDEF
12217
    OS_GETEUID_METHODDEF
12218
    OS_GETGID_METHODDEF
12219
#ifdef HAVE_GETGROUPLIST
12220
    {"getgrouplist",    posix_getgrouplist, METH_VARARGS, posix_getgrouplist__doc__},
12221
#endif
12222
    OS_GETGROUPS_METHODDEF
12223
    OS_GETPID_METHODDEF
12224
    OS_GETPGRP_METHODDEF
12225
    OS_GETPPID_METHODDEF
12226
    OS_GETUID_METHODDEF
12227
    OS_GETLOGIN_METHODDEF
12228
    OS_KILL_METHODDEF
12229
    OS_KILLPG_METHODDEF
12230
    OS_PLOCK_METHODDEF
12231
#ifdef MS_WINDOWS
12232
    OS_STARTFILE_METHODDEF
12233
#endif
12234
    OS_SETUID_METHODDEF
12235
    OS_SETEUID_METHODDEF
12236
    OS_SETREUID_METHODDEF
12237
    OS_SETGID_METHODDEF
12238
    OS_SETEGID_METHODDEF
12239
    OS_SETREGID_METHODDEF
12240
    OS_SETGROUPS_METHODDEF
12241
#ifdef HAVE_INITGROUPS
12242
    {"initgroups",      posix_initgroups, METH_VARARGS, posix_initgroups__doc__},
12243
#endif /* HAVE_INITGROUPS */
12244
    OS_GETPGID_METHODDEF
12245
    OS_SETPGRP_METHODDEF
12246
    OS_WAIT_METHODDEF
12247
    OS_WAIT3_METHODDEF
12248
    OS_WAIT4_METHODDEF
12249
    OS_WAITID_METHODDEF
12250
    OS_WAITPID_METHODDEF
12251
    OS_GETSID_METHODDEF
12252
    OS_SETSID_METHODDEF
12253
    OS_SETPGID_METHODDEF
12254
    OS_TCGETPGRP_METHODDEF
12255
    OS_TCSETPGRP_METHODDEF
12256
    OS_OPEN_METHODDEF
12257
    OS_CLOSE_METHODDEF
12258
    OS_CLOSERANGE_METHODDEF
12259
    OS_DEVICE_ENCODING_METHODDEF
12260
    OS_DUP_METHODDEF
12261
    OS_DUP2_METHODDEF
12262
    OS_LOCKF_METHODDEF
12263
    OS_LSEEK_METHODDEF
12264
    OS_READ_METHODDEF
12265
    OS_READV_METHODDEF
12266
    OS_PREAD_METHODDEF
12267
    OS_WRITE_METHODDEF
12268
    OS_WRITEV_METHODDEF
12269
    OS_PWRITE_METHODDEF
12270
#ifdef HAVE_SENDFILE
12271
    {"sendfile",        (PyCFunction)posix_sendfile, METH_VARARGS | METH_KEYWORDS,
12272
                            posix_sendfile__doc__},
12273
#endif
12274
    OS_FSTAT_METHODDEF
12275
    OS_ISATTY_METHODDEF
12276
    OS_PIPE_METHODDEF
12277
    OS_PIPE2_METHODDEF
12278
    OS_MKFIFO_METHODDEF
12279
    OS_MKNOD_METHODDEF
12280
    OS_MAJOR_METHODDEF
12281
    OS_MINOR_METHODDEF
12282
    OS_MAKEDEV_METHODDEF
12283
    OS_FTRUNCATE_METHODDEF
12284
    OS_TRUNCATE_METHODDEF
12285
    OS_POSIX_FALLOCATE_METHODDEF
12286
    OS_POSIX_FADVISE_METHODDEF
12287
    OS_PUTENV_METHODDEF
12288
    OS_UNSETENV_METHODDEF
12289
    OS_STRERROR_METHODDEF
12290
    OS_FCHDIR_METHODDEF
12291
    OS_FSYNC_METHODDEF
12292
    OS_SYNC_METHODDEF
12293
    OS_FDATASYNC_METHODDEF
12294
    OS_WCOREDUMP_METHODDEF
12295
    OS_WIFCONTINUED_METHODDEF
12296
    OS_WIFSTOPPED_METHODDEF
12297
    OS_WIFSIGNALED_METHODDEF
12298
    OS_WIFEXITED_METHODDEF
12299
    OS_WEXITSTATUS_METHODDEF
12300
    OS_WTERMSIG_METHODDEF
12301
    OS_WSTOPSIG_METHODDEF
12302
    OS_FSTATVFS_METHODDEF
12303
    OS_STATVFS_METHODDEF
12304
    OS_CONFSTR_METHODDEF
12305
    OS_SYSCONF_METHODDEF
12306
    OS_FPATHCONF_METHODDEF
12307
    OS_PATHCONF_METHODDEF
12308
    OS_ABORT_METHODDEF
12309
    OS__GETFULLPATHNAME_METHODDEF
12310
    OS__ISDIR_METHODDEF
12311
    OS__GETDISKUSAGE_METHODDEF
12312
    OS__GETFINALPATHNAME_METHODDEF
12313
    OS__GETVOLUMEPATHNAME_METHODDEF
12314
    OS_GETLOADAVG_METHODDEF
12315
    OS_URANDOM_METHODDEF
12316
    OS_SETRESUID_METHODDEF
12317
    OS_SETRESGID_METHODDEF
12318
    OS_GETRESUID_METHODDEF
12319
    OS_GETRESGID_METHODDEF
12320

12321
    OS_GETXATTR_METHODDEF
12322
    OS_SETXATTR_METHODDEF
12323
    OS_REMOVEXATTR_METHODDEF
12324
    OS_LISTXATTR_METHODDEF
12325

12326
#if defined(TERMSIZE_USE_CONIO) || defined(TERMSIZE_USE_IOCTL)
12327
    {"get_terminal_size", get_terminal_size, METH_VARARGS, termsize__doc__},
12328
#endif
12329
    OS_CPU_COUNT_METHODDEF
12330
    OS_GET_INHERITABLE_METHODDEF
12331
    OS_SET_INHERITABLE_METHODDEF
12332
    OS_GET_HANDLE_INHERITABLE_METHODDEF
12333
    OS_SET_HANDLE_INHERITABLE_METHODDEF
12334
#ifndef MS_WINDOWS
12335
    {"get_blocking", posix_get_blocking, METH_VARARGS, get_blocking__doc__},
12336
    {"set_blocking", posix_set_blocking, METH_VARARGS, set_blocking__doc__},
12337
#endif
12338
    {"scandir",         (PyCFunction)posix_scandir,
12339
                        METH_VARARGS | METH_KEYWORDS,
12340
                        posix_scandir__doc__},
12341
    OS_FSPATH_METHODDEF
12342
    OS_GETRANDOM_METHODDEF
12343
    {NULL,              NULL}            /* Sentinel */
12344
};
12345

12346

12347
#if defined(HAVE_SYMLINK) && defined(MS_WINDOWS)
12348
static int
12349
enable_symlink()
12350
{
12351
    HANDLE tok;
12352
    TOKEN_PRIVILEGES tok_priv;
12353
    LUID luid;
12354

12355
    if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ALL_ACCESS, &tok))
12356
        return 0;
12357

12358
    if (!LookupPrivilegeValue(NULL, SE_CREATE_SYMBOLIC_LINK_NAME, &luid))
12359
        return 0;
12360

12361
    tok_priv.PrivilegeCount = 1;
12362
    tok_priv.Privileges[0].Luid = luid;
12363
    tok_priv.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
12364

12365
    if (!AdjustTokenPrivileges(tok, FALSE, &tok_priv,
12366
                               sizeof(TOKEN_PRIVILEGES),
12367
                               (PTOKEN_PRIVILEGES) NULL, (PDWORD) NULL))
12368
        return 0;
12369

12370
    /* ERROR_NOT_ALL_ASSIGNED returned when the privilege can't be assigned. */
12371
    return GetLastError() == ERROR_NOT_ALL_ASSIGNED ? 0 : 1;
12372
}
12373
#endif /* defined(HAVE_SYMLINK) && defined(MS_WINDOWS) */
12374

12375
static int
12376
all_ins(PyObject *m)
12377
{
12378
#ifdef F_OK
12379
    if (PyModule_AddIntMacro(m, F_OK)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12380
#endif
12381
#ifdef R_OK
12382
    if (PyModule_AddIntMacro(m, R_OK)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12383
#endif
12384
#ifdef W_OK
12385
    if (PyModule_AddIntMacro(m, W_OK)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12386
#endif
12387
#ifdef X_OK
12388
    if (PyModule_AddIntMacro(m, X_OK)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12389
#endif
12390
#ifdef NGROUPS_MAX
12391
    if (PyModule_AddIntMacro(m, NGROUPS_MAX)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12392
#endif
12393
#ifdef TMP_MAX
12394
    if (PyModule_AddIntMacro(m, TMP_MAX)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12395
#endif
12396
#ifdef WCONTINUED
12397
    if (PyModule_AddIntMacro(m, WCONTINUED)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12398
#endif
12399
#ifdef WNOHANG
12400
    if (PyModule_AddIntMacro(m, WNOHANG)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12401
#endif
12402
#ifdef WUNTRACED
12403
    if (PyModule_AddIntMacro(m, WUNTRACED)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12404
#endif
12405
#ifdef O_RDONLY
12406
    if (PyModule_AddIntMacro(m, O_RDONLY)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12407
#endif
12408
#ifdef O_WRONLY
12409
    if (PyModule_AddIntMacro(m, O_WRONLY)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12410
#endif
12411
#ifdef O_RDWR
12412
    if (PyModule_AddIntMacro(m, O_RDWR)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12413
#endif
12414
#ifdef O_NDELAY
12415
    if (PyModule_AddIntMacro(m, O_NDELAY)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12416
#endif
12417
#ifdef O_NONBLOCK
12418
    if (PyModule_AddIntMacro(m, O_NONBLOCK)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12419
#endif
12420
#ifdef O_APPEND
12421
    if (PyModule_AddIntMacro(m, O_APPEND)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12422
#endif
12423
#ifdef O_DSYNC
12424
    if (PyModule_AddIntMacro(m, O_DSYNC)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12425
#endif
12426
#ifdef O_RSYNC
12427
    if (PyModule_AddIntMacro(m, O_RSYNC)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12428
#endif
12429
#ifdef O_SYNC
12430
    if (PyModule_AddIntMacro(m, O_SYNC)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12431
#endif
12432
#ifdef O_NOCTTY
12433
    if (PyModule_AddIntMacro(m, O_NOCTTY)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12434
#endif
12435
#ifdef O_CREAT
12436
    if (PyModule_AddIntMacro(m, O_CREAT)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12437
#endif
12438
#ifdef O_EXCL
12439
    if (PyModule_AddIntMacro(m, O_EXCL)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12440
#endif
12441
#ifdef O_TRUNC
12442
    if (PyModule_AddIntMacro(m, O_TRUNC)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12443
#endif
12444
#ifdef O_BINARY
12445
    if (PyModule_AddIntMacro(m, O_BINARY)) return -1;
12446
#endif
12447
#ifdef O_TEXT
12448
    if (PyModule_AddIntMacro(m, O_TEXT)) return -1;
12449
#endif
12450
#ifdef O_XATTR
12451
    if (PyModule_AddIntMacro(m, O_XATTR)) return -1;
12452
#endif
12453
#ifdef O_LARGEFILE
12454
    if (PyModule_AddIntMacro(m, O_LARGEFILE)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12455
#endif
12456
#ifndef __GNU__
12457
#ifdef O_SHLOCK
12458
    if (PyModule_AddIntMacro(m, O_SHLOCK)) return -1;
12459
#endif
12460
#ifdef O_EXLOCK
12461
    if (PyModule_AddIntMacro(m, O_EXLOCK)) return -1;
12462
#endif
12463
#endif
12464
#ifdef O_EXEC
12465
    if (PyModule_AddIntMacro(m, O_EXEC)) return -1;
12466
#endif
12467
#ifdef O_SEARCH
12468
    if (PyModule_AddIntMacro(m, O_SEARCH)) return -1;
12469
#endif
12470
#ifdef O_PATH
12471
    if (PyModule_AddIntMacro(m, O_PATH)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12472
#endif
12473
#ifdef O_TTY_INIT
12474
    if (PyModule_AddIntMacro(m, O_TTY_INIT)) return -1;
12475
#endif
12476
#ifdef O_TMPFILE
12477
    if (PyModule_AddIntMacro(m, O_TMPFILE)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12478
#endif
12479
#ifdef PRIO_PROCESS
12480
    if (PyModule_AddIntMacro(m, PRIO_PROCESS)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12481
#endif
12482
#ifdef PRIO_PGRP
12483
    if (PyModule_AddIntMacro(m, PRIO_PGRP)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12484
#endif
12485
#ifdef PRIO_USER
12486
    if (PyModule_AddIntMacro(m, PRIO_USER)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12487
#endif
12488
#ifdef O_CLOEXEC
12489
    if (PyModule_AddIntMacro(m, O_CLOEXEC)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12490
#endif
12491
#ifdef O_ACCMODE
12492
    if (PyModule_AddIntMacro(m, O_ACCMODE)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12493
#endif
12494

12495

12496
#ifdef SEEK_HOLE
12497
    if (PyModule_AddIntMacro(m, SEEK_HOLE)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12498
#endif
12499
#ifdef SEEK_DATA
12500
    if (PyModule_AddIntMacro(m, SEEK_DATA)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12501
#endif
12502

12503
/* MS Windows */
12504
#ifdef O_NOINHERIT
12505
    /* Don't inherit in child processes. */
12506
    if (PyModule_AddIntMacro(m, O_NOINHERIT)) return -1;
12507
#endif
12508
#ifdef _O_SHORT_LIVED
12509
    /* Optimize for short life (keep in memory). */
12510
    /* MS forgot to define this one with a non-underscore form too. */
12511
    if (PyModule_AddIntConstant(m, "O_SHORT_LIVED", _O_SHORT_LIVED)) return -1;
12512
#endif
12513
#ifdef O_TEMPORARY
12514
    /* Automatically delete when last handle is closed. */
12515
    if (PyModule_AddIntMacro(m, O_TEMPORARY)) return -1;
12516
#endif
12517
#ifdef O_RANDOM
12518
    /* Optimize for random access. */
12519
    if (PyModule_AddIntMacro(m, O_RANDOM)) return -1;
12520
#endif
12521
#ifdef O_SEQUENTIAL
12522
    /* Optimize for sequential access. */
12523
    if (PyModule_AddIntMacro(m, O_SEQUENTIAL)) return -1;
12524
#endif
12525

12526
/* GNU extensions. */
12527
#ifdef O_ASYNC
12528
    /* Send a SIGIO signal whenever input or output
12529
       becomes available on file descriptor */
12530
    if (PyModule_AddIntMacro(m, O_ASYNC)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12531
#endif
12532
#ifdef O_DIRECT
12533
    /* Direct disk access. */
12534
    if (PyModule_AddIntMacro(m, O_DIRECT)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12535
#endif
12536
#ifdef O_DIRECTORY
12537
    /* Must be a directory.      */
12538
    if (PyModule_AddIntMacro(m, O_DIRECTORY)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12539
#endif
12540
#ifdef O_NOFOLLOW
12541
    /* Do not follow links.      */
12542
    if (PyModule_AddIntMacro(m, O_NOFOLLOW)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12543
#endif
12544
#ifdef O_NOLINKS
12545
    /* Fails if link count of the named file is greater than 1 */
12546
    if (PyModule_AddIntMacro(m, O_NOLINKS)) return -1;
12547
#endif
12548
#ifdef O_NOATIME
12549
    /* Do not update the access time. */
12550
    if (PyModule_AddIntMacro(m, O_NOATIME)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12551
#endif
12552

12553
    /* These come from sysexits.h */
12554
#ifdef EX_OK
12555
    if (PyModule_AddIntMacro(m, EX_OK)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12556
#endif /* EX_OK */
12557
#ifdef EX_USAGE
12558
    if (PyModule_AddIntMacro(m, EX_USAGE)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12559
#endif /* EX_USAGE */
12560
#ifdef EX_DATAERR
12561
    if (PyModule_AddIntMacro(m, EX_DATAERR)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12562
#endif /* EX_DATAERR */
12563
#ifdef EX_NOINPUT
12564
    if (PyModule_AddIntMacro(m, EX_NOINPUT)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12565
#endif /* EX_NOINPUT */
12566
#ifdef EX_NOUSER
12567
    if (PyModule_AddIntMacro(m, EX_NOUSER)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12568
#endif /* EX_NOUSER */
12569
#ifdef EX_NOHOST
12570
    if (PyModule_AddIntMacro(m, EX_NOHOST)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12571
#endif /* EX_NOHOST */
12572
#ifdef EX_UNAVAILABLE
12573
    if (PyModule_AddIntMacro(m, EX_UNAVAILABLE)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12574
#endif /* EX_UNAVAILABLE */
12575
#ifdef EX_SOFTWARE
12576
    if (PyModule_AddIntMacro(m, EX_SOFTWARE)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12577
#endif /* EX_SOFTWARE */
12578
#ifdef EX_OSERR
12579
    if (PyModule_AddIntMacro(m, EX_OSERR)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12580
#endif /* EX_OSERR */
12581
#ifdef EX_OSFILE
12582
    if (PyModule_AddIntMacro(m, EX_OSFILE)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12583
#endif /* EX_OSFILE */
12584
#ifdef EX_CANTCREAT
12585
    if (PyModule_AddIntMacro(m, EX_CANTCREAT)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12586
#endif /* EX_CANTCREAT */
12587
#ifdef EX_IOERR
12588
    if (PyModule_AddIntMacro(m, EX_IOERR)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12589
#endif /* EX_IOERR */
12590
#ifdef EX_TEMPFAIL
12591
    if (PyModule_AddIntMacro(m, EX_TEMPFAIL)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12592
#endif /* EX_TEMPFAIL */
12593
#ifdef EX_PROTOCOL
12594
    if (PyModule_AddIntMacro(m, EX_PROTOCOL)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12595
#endif /* EX_PROTOCOL */
12596
#ifdef EX_NOPERM
12597
    if (PyModule_AddIntMacro(m, EX_NOPERM)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12598
#endif /* EX_NOPERM */
12599
#ifdef EX_CONFIG
12600
    if (PyModule_AddIntMacro(m, EX_CONFIG)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12601
#endif /* EX_CONFIG */
12602
#ifdef EX_NOTFOUND
12603
    if (PyModule_AddIntMacro(m, EX_NOTFOUND)) return -1;
12604
#endif /* EX_NOTFOUND */
12605

12606
    /* statvfs */
12607
#ifdef ST_RDONLY
12608
    if (PyModule_AddIntMacro(m, ST_RDONLY)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12609
#endif /* ST_RDONLY */
12610
#ifdef ST_NOSUID
12611
    if (PyModule_AddIntMacro(m, ST_NOSUID)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12612
#endif /* ST_NOSUID */
12613

12614
       /* GNU extensions */
12615
#ifdef ST_NODEV
12616
    if (PyModule_AddIntMacro(m, ST_NODEV)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12617
#endif /* ST_NODEV */
12618
#ifdef ST_NOEXEC
12619
    if (PyModule_AddIntMacro(m, ST_NOEXEC)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12620
#endif /* ST_NOEXEC */
12621
#ifdef ST_SYNCHRONOUS
12622
    if (PyModule_AddIntMacro(m, ST_SYNCHRONOUS)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12623
#endif /* ST_SYNCHRONOUS */
12624
#ifdef ST_MANDLOCK
12625
    if (PyModule_AddIntMacro(m, ST_MANDLOCK)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12626
#endif /* ST_MANDLOCK */
12627
#ifdef ST_WRITE
12628
    if (PyModule_AddIntMacro(m, ST_WRITE)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12629
#endif /* ST_WRITE */
12630
#ifdef ST_APPEND
12631
    if (PyModule_AddIntMacro(m, ST_APPEND)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12632
#endif /* ST_APPEND */
12633
#ifdef ST_NOATIME
12634
    if (PyModule_AddIntMacro(m, ST_NOATIME)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12635
#endif /* ST_NOATIME */
12636
#ifdef ST_NODIRATIME
12637
    if (PyModule_AddIntMacro(m, ST_NODIRATIME)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12638
#endif /* ST_NODIRATIME */
12639
#ifdef ST_RELATIME
12640
    if (PyModule_AddIntMacro(m, ST_RELATIME)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12641
#endif /* ST_RELATIME */
12642

12643
    /* FreeBSD sendfile() constants */
12644
#ifdef SF_NODISKIO
12645
    if (PyModule_AddIntMacro(m, SF_NODISKIO)) return -1;
12646
#endif
12647
#ifdef SF_MNOWAIT
12648
    if (PyModule_AddIntMacro(m, SF_MNOWAIT)) return -1;
12649
#endif
12650
#ifdef SF_SYNC
12651
    if (PyModule_AddIntMacro(m, SF_SYNC)) return -1;
12652
#endif
12653

12654
    /* constants for posix_fadvise */
12655
#ifdef POSIX_FADV_NORMAL
12656
    if (PyModule_AddIntMacro(m, POSIX_FADV_NORMAL)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12657
#endif
12658
#ifdef POSIX_FADV_SEQUENTIAL
12659
    if (PyModule_AddIntMacro(m, POSIX_FADV_SEQUENTIAL)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12660
#endif
12661
#ifdef POSIX_FADV_RANDOM
12662
    if (PyModule_AddIntMacro(m, POSIX_FADV_RANDOM)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12663
#endif
12664
#ifdef POSIX_FADV_NOREUSE
12665
    if (PyModule_AddIntMacro(m, POSIX_FADV_NOREUSE)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12666
#endif
12667
#ifdef POSIX_FADV_WILLNEED
12668
    if (PyModule_AddIntMacro(m, POSIX_FADV_WILLNEED)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12669
#endif
12670
#ifdef POSIX_FADV_DONTNEED
12671
    if (PyModule_AddIntMacro(m, POSIX_FADV_DONTNEED)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12672
#endif
12673

12674
    /* constants for waitid */
12675
#if defined(HAVE_SYS_WAIT_H) && defined(HAVE_WAITID)
12676
    if (PyModule_AddIntMacro(m, P_PID)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12677
    if (PyModule_AddIntMacro(m, P_PGID)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12678
    if (PyModule_AddIntMacro(m, P_ALL)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12679
#endif
12680
#ifdef WEXITED
12681
    if (PyModule_AddIntMacro(m, WEXITED)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12682
#endif
12683
#ifdef WNOWAIT
12684
    if (PyModule_AddIntMacro(m, WNOWAIT)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12685
#endif
12686
#ifdef WSTOPPED
12687
    if (PyModule_AddIntMacro(m, WSTOPPED)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12688
#endif
12689
#ifdef CLD_EXITED
12690
    if (PyModule_AddIntMacro(m, CLD_EXITED)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12691
#endif
12692
#ifdef CLD_DUMPED
12693
    if (PyModule_AddIntMacro(m, CLD_DUMPED)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12694
#endif
12695
#ifdef CLD_TRAPPED
12696
    if (PyModule_AddIntMacro(m, CLD_TRAPPED)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12697
#endif
12698
#ifdef CLD_CONTINUED
12699
    if (PyModule_AddIntMacro(m, CLD_CONTINUED)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12700
#endif
12701

12702
    /* constants for lockf */
12703
#ifdef F_LOCK
12704
    if (PyModule_AddIntMacro(m, F_LOCK)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12705
#endif
12706
#ifdef F_TLOCK
12707
    if (PyModule_AddIntMacro(m, F_TLOCK)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12708
#endif
12709
#ifdef F_ULOCK
12710
    if (PyModule_AddIntMacro(m, F_ULOCK)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12711
#endif
12712
#ifdef F_TEST
12713
    if (PyModule_AddIntMacro(m, F_TEST)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12714
#endif
12715

12716
#ifdef HAVE_SPAWNV
12717
    if (PyModule_AddIntConstant(m, "P_WAIT", _P_WAIT)) return -1;
12718
    if (PyModule_AddIntConstant(m, "P_NOWAIT", _P_NOWAIT)) return -1;
12719
    if (PyModule_AddIntConstant(m, "P_OVERLAY", _OLD_P_OVERLAY)) return -1;
12720
    if (PyModule_AddIntConstant(m, "P_NOWAITO", _P_NOWAITO)) return -1;
12721
    if (PyModule_AddIntConstant(m, "P_DETACH", _P_DETACH)) return -1;
12722
#endif
12723

12724
#ifdef HAVE_SCHED_H
12725
#ifdef SCHED_OTHER
12726
    if (PyModule_AddIntMacro(m, SCHED_OTHER)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12727
#endif
12728
#ifdef SCHED_FIFO
12729
    if (PyModule_AddIntMacro(m, SCHED_FIFO)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12730
#endif
12731
#ifdef SCHED_RR
12732
    if (PyModule_AddIntMacro(m, SCHED_RR)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12733
#endif
12734
#ifdef SCHED_SPORADIC
12735
    if (PyModule_AddIntMacro(m, SCHED_SPORADIC) return -1;
12736
#endif
12737
#ifdef SCHED_BATCH
12738
    if (PyModule_AddIntMacro(m, SCHED_BATCH)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12739
#endif
12740
#ifdef SCHED_IDLE
12741
    if (PyModule_AddIntMacro(m, SCHED_IDLE)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12742
#endif
12743
#ifdef SCHED_RESET_ON_FORK
12744
    if (PyModule_AddIntMacro(m, SCHED_RESET_ON_FORK)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12745
#endif
12746
#ifdef SCHED_SYS
12747
    if (PyModule_AddIntMacro(m, SCHED_SYS)) return -1;
12748
#endif
12749
#ifdef SCHED_IA
12750
    if (PyModule_AddIntMacro(m, SCHED_IA)) return -1;
12751
#endif
12752
#ifdef SCHED_FSS
12753
    if (PyModule_AddIntMacro(m, SCHED_FSS)) return -1;
12754
#endif
12755
#ifdef SCHED_FX
12756
    if (PyModule_AddIntConstant(m, "SCHED_FX", SCHED_FSS)) return -1;
12757
#endif
12758
#endif
12759

12760
#ifdef USE_XATTRS
12761
    if (PyModule_AddIntMacro(m, XATTR_CREATE)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12762
    if (PyModule_AddIntMacro(m, XATTR_REPLACE)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12763
    if (PyModule_AddIntMacro(m, XATTR_SIZE_MAX)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12764
#endif
12765

12766
#if HAVE_DECL_RTLD_LAZY
12767
    if (PyModule_AddIntMacro(m, RTLD_LAZY)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12768
#endif
12769
#if HAVE_DECL_RTLD_NOW
12770
    if (PyModule_AddIntMacro(m, RTLD_NOW)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12771
#endif
12772
#if HAVE_DECL_RTLD_GLOBAL
12773
    if (PyModule_AddIntMacro(m, RTLD_GLOBAL)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12774
#endif
12775
#if HAVE_DECL_RTLD_LOCAL
12776
    if (PyModule_AddIntMacro(m, RTLD_LOCAL)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12777
#endif
12778
#if HAVE_DECL_RTLD_NODELETE
12779
    if (PyModule_AddIntMacro(m, RTLD_NODELETE)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12780
#endif
12781
#if HAVE_DECL_RTLD_NOLOAD
12782
    if (PyModule_AddIntMacro(m, RTLD_NOLOAD)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12783
#endif
12784
#if HAVE_DECL_RTLD_DEEPBIND
12785
    if (PyModule_AddIntMacro(m, RTLD_DEEPBIND)) return -1;
inline
        
PyModule_AddIntConstant will not be inlined into all_ins because its definition is unavailable 
all_ins
12786
#endif
12787

12788
#ifdef HAVE_GETRANDOM_SYSCALL
12789
    if (PyModule_AddIntMacro(m, GRND_RANDOM)) return -1;
12790
    if (PyModule_AddIntMacro(m, GRND_NONBLOCK)) return -1;
12791
#endif
12792

12793
    return 0;
12794
}
12795

12796

12797
static struct PyModuleDef posixmodule = {
12798
    PyModuleDef_HEAD_INIT,
12799
    MODNAME,
12800
    posix__doc__,
12801
    -1,
12802
    posix_methods,
12803
    NULL,
12804
    NULL,
12805
    NULL,
12806
    NULL
12807
};
12808

12809

12810
static const char * const have_functions[] = {
12811

12812
#ifdef HAVE_FACCESSAT
12813
    "HAVE_FACCESSAT",
12814
#endif
12815

12816
#ifdef HAVE_FCHDIR
12817
    "HAVE_FCHDIR",
12818
#endif
12819

12820
#ifdef HAVE_FCHMOD
12821
    "HAVE_FCHMOD",
12822
#endif
12823

12824
#ifdef HAVE_FCHMODAT
12825
    "HAVE_FCHMODAT",
12826
#endif
12827

12828
#ifdef HAVE_FCHOWN
12829
    "HAVE_FCHOWN",
12830
#endif
12831

12832
#ifdef HAVE_FCHOWNAT
12833
    "HAVE_FCHOWNAT",
12834
#endif
12835

12836
#ifdef HAVE_FEXECVE
12837
    "HAVE_FEXECVE",
12838
#endif
12839

12840
#ifdef HAVE_FDOPENDIR
12841
    "HAVE_FDOPENDIR",
12842
#endif
12843

12844
#ifdef HAVE_FPATHCONF
12845
    "HAVE_FPATHCONF",
12846
#endif
12847

12848
#ifdef HAVE_FSTATAT
12849
    "HAVE_FSTATAT",
12850
#endif
12851

12852
#ifdef HAVE_FSTATVFS
12853
    "HAVE_FSTATVFS",
12854
#endif
12855

12856
#if defined HAVE_FTRUNCATE || defined MS_WINDOWS
12857
    "HAVE_FTRUNCATE",
12858
#endif
12859

12860
#ifdef HAVE_FUTIMENS
12861
    "HAVE_FUTIMENS",
12862
#endif
12863

12864
#ifdef HAVE_FUTIMES
12865
    "HAVE_FUTIMES",
12866
#endif
12867

12868
#ifdef HAVE_FUTIMESAT
12869
    "HAVE_FUTIMESAT",
12870
#endif
12871

12872
#ifdef HAVE_LINKAT
12873
    "HAVE_LINKAT",
12874
#endif
12875

12876
#ifdef HAVE_LCHFLAGS
12877
    "HAVE_LCHFLAGS",
12878
#endif
12879

12880
#ifdef HAVE_LCHMOD
12881
    "HAVE_LCHMOD",
12882
#endif
12883

12884
#ifdef HAVE_LCHOWN
12885
    "HAVE_LCHOWN",
12886
#endif
12887

12888
#ifdef HAVE_LSTAT
12889
    "HAVE_LSTAT",
12890
#endif
12891

12892
#ifdef HAVE_LUTIMES
12893
    "HAVE_LUTIMES",
12894
#endif
12895

12896
#ifdef HAVE_MKDIRAT
12897
    "HAVE_MKDIRAT",
12898
#endif
12899

12900
#ifdef HAVE_MKFIFOAT
12901
    "HAVE_MKFIFOAT",
12902
#endif
12903

12904
#ifdef HAVE_MKNODAT
12905
    "HAVE_MKNODAT",
12906
#endif
12907

12908
#ifdef HAVE_OPENAT
12909
    "HAVE_OPENAT",
12910
#endif
12911

12912
#ifdef HAVE_READLINKAT
12913
    "HAVE_READLINKAT",
12914
#endif
12915

12916
#ifdef HAVE_RENAMEAT
12917
    "HAVE_RENAMEAT",
12918
#endif
12919

12920
#ifdef HAVE_SYMLINKAT
12921
    "HAVE_SYMLINKAT",
12922
#endif
12923

12924
#ifdef HAVE_UNLINKAT
12925
    "HAVE_UNLINKAT",
12926
#endif
12927

12928
#ifdef HAVE_UTIMENSAT
12929
    "HAVE_UTIMENSAT",
12930
#endif
12931

12932
#ifdef MS_WINDOWS
12933
    "MS_WINDOWS",
12934
#endif
12935

12936
    NULL
12937
};
12938

12939

12940
PyMODINIT_FUNC
12941
INITFUNC(void)
12942
{
12943
    PyObject *m, *v;
12944
    PyObject *list;
12945
    const char * const *trace;
12946

12947
#if defined(HAVE_SYMLINK) && defined(MS_WINDOWS)
12948
    win32_can_symlink = enable_symlink();
12949
#endif
12950

12951
    m = PyModule_Create(&posixmodule);
inline
        
PyModule_Create2 will not be inlined into PyInit_posix because its definition is unavailable 
PyInit_posix
12952
    if (m == NULL)
12953
        return NULL;
12954

12955
    /* Initialize environ dictionary */
12956
    v = convertenviron();
inline
        
convertenviron can be inlined into PyInit_posix with cost=-14415 (threshold=250) 
PyInit_posix
inline
        
convertenviron inlined into PyInit_posix 
PyInit_posix
12957
    Py_XINCREF(v);
gvn
    
load of type i64 not eliminated because it is clobbered by call 
PyInit_posix
12958
    if (v == NULL || PyModule_AddObject(m, "environ", v) != 0)
inline
                     
PyModule_AddObject will not be inlined into PyInit_posix because its definition is unavailable 
PyInit_posix
12959
        return NULL;
12960
    Py_DECREF(v);
gvn
    
load of type i64 not eliminated because it is clobbered by call 
PyInit_posix
12961

12962
    if (all_ins(m))
inline
        
all_ins can be inlined into PyInit_posix with cost=-9540 (threshold=250) 
PyInit_posix
inline
        
all_ins inlined into PyInit_posix 
PyInit_posix
12963
        return NULL;
12964

12965
    if (setup_confname_tables(m))
inline
        
setup_confname_tables can be inlined into PyInit_posix with cost=-14860 (threshold=250) 
PyInit_posix
inline
        
setup_confname_tables inlined into PyInit_posix 
PyInit_posix
12966
        return NULL;
12967

12968
    Py_INCREF(PyExc_OSError);
gvn
    
load of type %struct._object* not eliminated because it is clobbered by call 
PyInit_posix
12969
    PyModule_AddObject(m, "error", PyExc_OSError);
inline
    
PyModule_AddObject will not be inlined into PyInit_posix because its definition is unavailable 
PyInit_posix
12970

12971
#ifdef HAVE_PUTENV
12972
    if (posix_putenv_garbage == NULL)
gvn
        
load of type %struct._object* not eliminated because it is clobbered by call 
PyInit_posix
12973
        posix_putenv_garbage = PyDict_New();
inline
                               
PyDict_New will not be inlined into PyInit_posix because its definition is unavailable 
PyInit_posix
12974
#endif
12975

12976
    if (!initialized) {
12977
#if defined(HAVE_WAITID) && !defined(__APPLE__)
12978
        waitid_result_desc.name = MODNAME ".waitid_result";
12979
        if (PyStructSequence_InitType2(&WaitidResultType, &waitid_result_desc) < 0)
inline
            
PyStructSequence_InitType2 will not be inlined into PyInit_posix because its definition is unavailable 
PyInit_posix
12980
            return NULL;
12981
#endif
12982

12983
        stat_result_desc.name = "os.stat_result"; /* see issue #19209 */
12984
        stat_result_desc.fields[7].name = PyStructSequence_UnnamedField;
gvn
                                          
load of type i64 not eliminated because it is clobbered by call 
PyInit_posix
gvn
                         
load of type %struct.PyStructSequence_Field* not eliminated because it is clobbered by call 
PyInit_posix
12985
        stat_result_desc.fields[8].name = PyStructSequence_UnnamedField;
gvn
                                          
load of type i64 not eliminated in favor of load because it is clobbered by store 
PyInit_posix
12986
        stat_result_desc.fields[9].name = PyStructSequence_UnnamedField;
gvn
                                          
load of type i64 not eliminated because it is clobbered by store 
PyInit_posix
12987
        if (PyStructSequence_InitType2(&StatResultType, &stat_result_desc) < 0)
inline
            
PyStructSequence_InitType2 will not be inlined into PyInit_posix because its definition is unavailable 
PyInit_posix
12988
            return NULL;
12989
        structseq_new = StatResultType.tp_new;
gvn
                                       
load of type i64 not eliminated because it is clobbered by call 
PyInit_posix
12990
        StatResultType.tp_new = statresult_new;
12991

12992
        statvfs_result_desc.name = "os.statvfs_result"; /* see issue #19209 */
12993
        if (PyStructSequence_InitType2(&StatVFSResultType,
inline
            
PyStructSequence_InitType2 will not be inlined into PyInit_posix because its definition is unavailable 
PyInit_posix
12994
                                       &statvfs_result_desc) < 0)
12995
            return NULL;
12996
#ifdef NEED_TICKS_PER_SECOND
12997
#  if defined(HAVE_SYSCONF) && defined(_SC_CLK_TCK)
12998
        ticks_per_second = sysconf(_SC_CLK_TCK);
inline
                           
sysconf will not be inlined into PyInit_posix because its definition is unavailable 
PyInit_posix
12999
#  elif defined(HZ)
13000
        ticks_per_second = HZ;
13001
#  else
13002
        ticks_per_second = 60; /* magic fallback value; may be bogus */
13003
#  endif
13004
#endif
13005

13006
#if defined(HAVE_SCHED_SETPARAM) || defined(HAVE_SCHED_SETSCHEDULER)
13007
        sched_param_desc.name = MODNAME ".sched_param";
13008
        if (PyStructSequence_InitType2(&SchedParamType, &sched_param_desc) < 0)
inline
            
PyStructSequence_InitType2 will not be inlined into PyInit_posix because its definition is unavailable 
PyInit_posix
13009
            return NULL;
13010
        SchedParamType.tp_new = os_sched_param;
13011
#endif
13012

13013
        /* initialize TerminalSize_info */
13014
        if (PyStructSequence_InitType2(&TerminalSizeType,
inline
            
PyStructSequence_InitType2 will not be inlined into PyInit_posix because its definition is unavailable 
PyInit_posix
13015
                                       &TerminalSize_desc) < 0)
13016
            return NULL;
13017

13018
        /* initialize scandir types */
13019
        if (PyType_Ready(&ScandirIteratorType) < 0)
inline
            
PyType_Ready will not be inlined into PyInit_posix because its definition is unavailable 
PyInit_posix
13020
            return NULL;
13021
        if (PyType_Ready(&DirEntryType) < 0)
inline
            
PyType_Ready will not be inlined into PyInit_posix because its definition is unavailable 
PyInit_posix
13022
            return NULL;
13023
    }
13024
#if defined(HAVE_WAITID) && !defined(__APPLE__)
13025
    Py_INCREF((PyObject*) &WaitidResultType);
gvn
    
load of type i64 not eliminated because it is clobbered by call 
PyInit_posix
13026
    PyModule_AddObject(m, "waitid_result", (PyObject*) &WaitidResultType);
inline
    
PyModule_AddObject will not be inlined into PyInit_posix because its definition is unavailable 
PyInit_posix
13027
#endif
13028
    Py_INCREF((PyObject*) &StatResultType);
gvn
    
load of type i64 not eliminated because it is clobbered by call 
PyInit_posix
13029
    PyModule_AddObject(m, "stat_result", (PyObject*) &StatResultType);
inline
    
PyModule_AddObject will not be inlined into PyInit_posix because its definition is unavailable 
PyInit_posix
13030
    Py_INCREF((PyObject*) &StatVFSResultType);
gvn
    
load of type i64 not eliminated because it is clobbered by call 
PyInit_posix
13031
    PyModule_AddObject(m, "statvfs_result",
inline
    
PyModule_AddObject will not be inlined into PyInit_posix because its definition is unavailable 
PyInit_posix
13032
                       (PyObject*) &StatVFSResultType);
13033

13034
#if defined(HAVE_SCHED_SETPARAM) || defined(HAVE_SCHED_SETSCHEDULER)
13035
    Py_INCREF(&SchedParamType);
gvn
    
load of type i64 not eliminated because it is clobbered by call 
PyInit_posix
13036
    PyModule_AddObject(m, "sched_param", (PyObject *)&SchedParamType);
inline
    
PyModule_AddObject will not be inlined into PyInit_posix because its definition is unavailable 
PyInit_posix
13037
#endif
13038

13039
    times_result_desc.name = MODNAME ".times_result";
13040
    if (PyStructSequence_InitType2(&TimesResultType, &times_result_desc) < 0)
inline
        
PyStructSequence_InitType2 will not be inlined into PyInit_posix because its definition is unavailable 
PyInit_posix
13041
        return NULL;
13042
    PyModule_AddObject(m, "times_result", (PyObject *)&TimesResultType);
inline
    
PyModule_AddObject will not be inlined into PyInit_posix because its definition is unavailable 
PyInit_posix
13043

13044
    uname_result_desc.name = MODNAME ".uname_result";
13045
    if (PyStructSequence_InitType2(&UnameResultType, &uname_result_desc) < 0)
inline
        
PyStructSequence_InitType2 will not be inlined into PyInit_posix because its definition is unavailable 
PyInit_posix
13046
        return NULL;
13047
    PyModule_AddObject(m, "uname_result", (PyObject *)&UnameResultType);
inline
    
PyModule_AddObject will not be inlined into PyInit_posix because its definition is unavailable 
PyInit_posix
13048

13049
#ifdef __APPLE__
13050
    /*
13051
     * Step 2 of weak-linking support on Mac OS X.
13052
     *
13053
     * The code below removes functions that are not available on the
13054
     * currently active platform.
13055
     *
13056
     * This block allow one to use a python binary that was build on
13057
     * OSX 10.4 on OSX 10.3, without losing access to new APIs on
13058
     * OSX 10.4.
13059
     */
13060
#ifdef HAVE_FSTATVFS
13061
    if (fstatvfs == NULL) {
13062
        if (PyObject_DelAttrString(m, "fstatvfs") == -1) {
13063
            return NULL;
13064
        }
13065
    }
13066
#endif /* HAVE_FSTATVFS */
13067

13068
#ifdef HAVE_STATVFS
13069
    if (statvfs == NULL) {
13070
        if (PyObject_DelAttrString(m, "statvfs") == -1) {
13071
            return NULL;
13072
        }
13073
    }
13074
#endif /* HAVE_STATVFS */
13075

13076
# ifdef HAVE_LCHOWN
13077
    if (lchown == NULL) {
13078
        if (PyObject_DelAttrString(m, "lchown") == -1) {
13079
            return NULL;
13080
        }
13081
    }
13082
#endif /* HAVE_LCHOWN */
13083

13084

13085
#endif /* __APPLE__ */
13086

13087
    Py_INCREF(&TerminalSizeType);
gvn
    
load of type i64 not eliminated because it is clobbered by call 
PyInit_posix
13088
    PyModule_AddObject(m, "terminal_size", (PyObject*) &TerminalSizeType);
inline
    
PyModule_AddObject will not be inlined into PyInit_posix because its definition is unavailable 
PyInit_posix
13089

13090
    billion = PyLong_FromLong(1000000000);
inline
              
PyLong_FromLong will not be inlined into PyInit_posix because its definition is unavailable 
PyInit_posix
13091
    if (!billion)
13092
        return NULL;
13093

13094
    /* suppress "function not used" warnings */
13095
    {
13096
    int ignored;
13097
    fd_specified("", -1);
13098
    follow_symlinks_specified("", 1);
inline
    
follow_symlinks_specified can be inlined into PyInit_posix with cost=-40 (threshold=375) 
PyInit_posix
inline
    
follow_symlinks_specified inlined into PyInit_posix 
PyInit_posix
13099
    dir_fd_and_follow_symlinks_invalid("chmod", DEFAULT_DIR_FD, 1);
inline
    
dir_fd_and_follow_symlinks_invalid can be inlined into PyInit_posix with cost=-40 (threshold=375) 
PyInit_posix
inline
    
dir_fd_and_follow_symlinks_invalid inlined into PyInit_posix 
PyInit_posix
13100
    dir_fd_converter(Py_None, &ignored);
inline
    
dir_fd_converter can be inlined into PyInit_posix with cost=-35 (threshold=375) 
PyInit_posix
inline
    
dir_fd_converter inlined into PyInit_posix 
PyInit_posix
13101
    dir_fd_unavailable(Py_None, &ignored);
inline
    
dir_fd_unavailable can be inlined into PyInit_posix with cost=-15035 (threshold=375) 
PyInit_posix
inline
    
dir_fd_unavailable inlined into PyInit_posix 
PyInit_posix
13102
    }
13103

13104
    /*
13105
     * provide list of locally available functions
13106
     * so os.py can populate support_* lists
13107
     */
13108
    list = PyList_New(0);
inline
           
PyList_New will not be inlined into PyInit_posix because its definition is unavailable 
PyInit_posix
13109
    if (!list)
13110
        return NULL;
13111
    for (trace = have_functions; *trace; trace++) {
gvn
                                 
load of type i8* not eliminated because it is clobbered by call 
PyInit_posix
loop-vectorize
    
loop not vectorized: loop control flow is not understood by vectorizer 
PyInit_posix
loop-vectorize
    
loop not vectorized 
PyInit_posix
13112
        PyObject *unicode = PyUnicode_DecodeASCII(*trace, strlen(*trace), NULL);
inline
                                                          
strlen will not be inlined into PyInit_posix because its definition is unavailable 
PyInit_posix
inline
                            
PyUnicode_DecodeASCII will not be inlined into PyInit_posix because its definition is unavailable 
PyInit_posix
13113
        if (!unicode)
13114
            return NULL;
13115
        if (PyList_Append(list, unicode))
inline
            
PyList_Append will not be inlined into PyInit_posix because its definition is unavailable 
PyInit_posix
13116
            return NULL;
13117
        Py_DECREF(unicode);
gvn
        
load of type i64 not eliminated because it is clobbered by call 
PyInit_posix
13118
    }
13119
    PyModule_AddObject(m, "_have_functions", list);
inline
    
PyModule_AddObject will not be inlined into PyInit_posix because its definition is unavailable 
PyInit_posix
13120

13121
    Py_INCREF((PyObject *) &DirEntryType);
gvn
    
load of type i64 not eliminated because it is clobbered by call 
PyInit_posix
13122
    PyModule_AddObject(m, "DirEntry", (PyObject *)&DirEntryType);
inline
    
PyModule_AddObject will not be inlined into PyInit_posix because its definition is unavailable 
PyInit_posix
13123

13124
    initialized = 1;
13125

13126
    return m;
13127
}
13128

13129
#ifdef __cplusplus
13130
}
13131
#endif